Skip to content

Commit

Permalink
refactor(server): refactor start method to use async/await (#3245)
Browse files Browse the repository at this point in the history
  • Loading branch information
lusarz authored and johnjbarton committed Jan 1, 2019
1 parent 8a83990 commit acdd2dc
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/server.js
Expand Up @@ -114,21 +114,19 @@ class Server extends KarmaEventEmitter {
process.kill(process.pid, 'SIGINT')
}

start () {
async start () {
const config = this.get('config')
return Promise.all([
BundleUtils.bundleResourceIfNotExist('client/main.js', 'static/karma.js'),
BundleUtils.bundleResourceIfNotExist('context/main.js', 'static/context.js')
])
.then(() => NetUtils.bindAvailablePort(config.port, config.listenAddress))
.then((boundServer) => {
config.port = boundServer.address().port
this._boundServer = boundServer
this._injector.invoke(this._start, this)
})
.catch((err) => {
this.dieOnError(`Server start failed on port ${config.port}: ${err}`)
})
try {
await Promise.all([
BundleUtils.bundleResourceIfNotExist('client/main.js', 'static/karma.js'),
BundleUtils.bundleResourceIfNotExist('context/main.js', 'static/context.js')
])
this._boundServer = await NetUtils.bindAvailablePort(config.port, config.listenAddress)
config.port = this._boundServer.address().port
this._injector.invoke(this._start, this)
} catch (err) {
this.dieOnError(`Server start failed on port ${config.port}: ${err}`)
}
}

get (token) {
Expand Down

0 comments on commit acdd2dc

Please sign in to comment.