提交 6f814303 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

clean code

上级 bc8791e3
......@@ -45,13 +45,17 @@ class Bridge {
return this.inject()
.then(r => {
log.verbose('PuppetWebBridge', 'init() inject() return %s at attempt %d', r, attempt)
return r
return this
})
.catch(e => {
log.verbose('PuppetWebBridge', 'init() inject() attempt %d exception: %s', attempt, e.message)
throw e
})
})
.then(_ => {
log.verbose('PuppetWebBridge', 'init()-ed')
return this
})
.catch(e => {
log.warn('PuppetWebBridge', 'init() inject FINAL fail: %s', e.message)
throw e
......
......@@ -39,9 +39,10 @@ class Server extends EventEmitter {
, r => resolve(r), e => reject(e)
)
this.socketServer = this.createSocketIo(this.httpsServer)
}).then(r => {
log.verbose('PuppetWebServer', 'full init()-ed')
return true
return this
}).catch(e => {
log.error('PuppetWebServer', 'init() exception: %s', e.message)
throw e
......
......@@ -59,13 +59,13 @@ class PuppetWeb extends Puppet {
yield this.initAttach(this)
log.verbose('PuppetWeb', 'initAttach() done')
yield this.initServer()
this.server = yield this.initServer()
log.verbose('PuppetWeb', 'initServer() done')
yield this.initBrowser()
this.browser = yield this.initBrowser()
log.verbose('PuppetWeb', 'initBrowser() done')
yield this.initBridge()
this.bridge = yield this.initBridge()
log.verbose('PuppetWeb', 'initBridge() done')
})
.catch(e => { // Reject
......@@ -153,12 +153,12 @@ class PuppetWeb extends Puppet {
initBridge() {
log.verbose('PuppetWeb', 'initBridge()')
this.bridge = new Bridge({
const bridge = new Bridge({
puppet: this // use puppet instead of browser, is because browser might change(die) duaring run time
, port: this.port
})
return this.bridge.init()
return bridge.init()
.catch(e => {
if (this.browser.dead()) {
log.warn('PuppetWeb', 'initBridge() found browser dead, wait it to restore')
......@@ -184,8 +184,7 @@ class PuppetWeb extends Puppet {
server.on('log' , Event.onServerLog.bind(this))
server.on('ding' , Event.onServerDing.bind(this))
this.server = server
return this.server.init()
return server.init()
.catch(e => {
log.error('PuppetWeb', 'initServer() exception: %s', e.message)
throw e
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册