Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
9307921a
W
wechaty
项目概览
weixin_46011646
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9307921a
编写于
6月 06, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use co-routine to deal promise in init()
上级
aed688cb
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
101 addition
and
49 deletion
+101
-49
src/puppet-web.js
src/puppet-web.js
+101
-49
未找到文件。
src/puppet-web.js
浏览文件 @
9307921a
...
...
@@ -44,37 +44,120 @@ class PuppetWeb extends Puppet {
init
()
{
log
.
verbose
(
'
PuppetWeb
'
,
'
init()
'
)
return
this
.
initAttach
()
.
then
(
r
=>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
initAttach done: %s
'
,
r
)
return
this
.
initBrowser
()
return
co
.
call
(
this
,
function
*
()
{
yield
this
.
initAttach
(
this
)
log
.
verbose
(
'
PuppetWeb
'
,
'
initAttach() done
'
)
yield
this
.
initServer
()
log
.
verbose
(
'
PuppetWeb
'
,
'
initServer() done
'
)
yield
this
.
initBrowser
()
log
.
verbose
(
'
PuppetWeb
'
,
'
initBrowser() done
'
)
yield
this
.
initBridge
()
log
.
verbose
(
'
PuppetWeb
'
,
'
initBridge() done
'
)
return
this
})
.
then
(
r
=>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
initBrowser done: %s
'
,
r
)
return
this
.
initBridge
()
.
catch
(
e
=>
{
// Reject
log
.
error
(
'
PuppetWeb
'
,
e
)
throw
e
})
.
then
(
r
=>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
init
Bridge done: %s
'
,
r
)
return
this
.
initServer
()
.
then
(
()
=>
{
// Finally
log
.
verbose
(
'
PuppetWeb
'
,
'
init
() done
'
)
return
this
// for Chaining
})
.
then
(
r
=>
{
log
.
verbose
(
'
PuppetWeb
'
,
'
initServer done: %s
'
,
r
)
return
r
// return this.initAttach()
// .then(r => {
// log.verbose('PuppetWeb', 'initAttach done: %s', r)
// return this.initBrowser()
// })
// .then(r => {
// log.verbose('PuppetWeb', 'initBrowser done: %s', r)
// return this.initBridge()
// })
// .then(r => {
// log.verbose('PuppetWeb', 'initBridge done: %s', r)
// return this.initServer()
// })
// .then(r => {
// log.verbose('PuppetWeb', 'initServer done: %s', r)
// return r
// })
// .catch(e => { // Reject
// log.error('PuppetWeb', e)
// throw e
// })
// .then(r => { // Finally
// log.verbose('PuppetWeb', 'all initXXX done.')
// return this // for Chaining
// })
}
quit
()
{
log
.
verbose
(
'
PuppetWeb
'
,
'
quit()
'
)
return
co
.
call
(
this
,
function
*
()
{
if
(
this
.
bridge
)
{
yield
this
.
bridge
.
quit
()
this
.
bridge
=
null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without bridge
'
)
}
if
(
this
.
browser
)
{
yield
this
.
browser
.
quit
()
this
.
browser
=
null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without browser
'
)
}
if
(
this
.
server
)
{
yield
this
.
server
.
quit
()
this
.
server
=
null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without server
'
)
}
yield
this
.
initAttach
(
null
)
})
.
catch
(
e
=>
{
// Reject
log
.
error
(
'
PuppetWeb
'
,
e
)
throw
e
})
.
then
(
r
=>
{
// Finally
log
.
verbose
(
'
PuppetWeb
'
,
'
all initXXX done.
'
)
.
then
(
()
=>
{
// Finally
log
.
verbose
(
'
PuppetWeb
'
,
'
quit() done
'
)
return
this
// for Chaining
})
// let p = Promise.resolve(true)
// if (this.bridge) {
// p.then(this.bridge.quit.bind(this.bridge))
// this.bridge = null
// } else {
// log.warn('PuppetWeb', 'quit() without bridge')
// }
// if (this.browser) {
// p.then(this.browser.quit.bind(this.browser))
// this.browser = null
// } else {
// log.warn('PuppetWeb', 'quit() without browser')
// }
// if (this.server) {
// p.then(this.server.quit.bind(this.server))
// this.server = null
// } else {
// log.warn('PuppetWeb', 'quit() without server')
// }
// return p // return Promise
}
initAttach
()
{
initAttach
(
puppet
)
{
log
.
verbose
(
'
PuppetWeb
'
,
'
initAttach()
'
)
Contact
.
attach
(
this
)
Room
.
attach
(
this
)
Contact
.
attach
(
puppet
)
Room
.
attach
(
puppet
)
return
Promise
.
resolve
(
true
)
}
initBrowser
()
{
...
...
@@ -208,37 +291,6 @@ class PuppetWeb extends Puppet {
return
this
.
bridge
.
getLoginQrImgUrl
()
}
logined
()
{
return
!!
(
this
.
user
)
}
/**
* Interface Methods
*/
quit
()
{
log
.
verbose
(
'
PuppetWeb
'
,
'
quit()
'
)
let
p
=
Promise
.
resolve
(
true
)
if
(
this
.
bridge
)
{
p
.
then
(
this
.
bridge
.
quit
.
bind
(
this
.
bridge
))
this
.
bridge
=
null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without bridge
'
)
}
if
(
this
.
browser
)
{
p
.
then
(
this
.
browser
.
quit
.
bind
(
this
.
browser
))
this
.
browser
=
null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without browser
'
)
}
if
(
this
.
server
)
{
p
.
then
(
this
.
server
.
quit
.
bind
(
this
.
server
))
this
.
server
=
null
}
else
{
log
.
warn
(
'
PuppetWeb
'
,
'
quit() without server
'
)
}
return
p
// return Promise
}
}
module
.
exports
=
PuppetWeb
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录