Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

refactor: http-server util file #565

Merged
merged 1 commit into from
Dec 2, 2019
Merged

Conversation

PedroMiguelSS
Copy link
Contributor

This PR refactors echo server start() and stop() from callback to promise.

@alanshaw alanshaw merged commit 0605210 into master Dec 2, 2019
@alanshaw alanshaw deleted the refactor/http-server-util branch December 2, 2019 10:17
}
return server.listen(Object.assign({ port: defaultPort, host: '127.0.0.1' }, opts), cb)
}
server.start = (opts) => new Promise(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should handle errors while starting up:

server.start = (opts) => new Promise((resolve, reject) => {
  server.once('error', reject)
  server.listen(Object.assign({ port: defaultPort, host: '127.0.0.1' }, opts), () => {
    server.removeListener('error', reject)
    resolve()
  })
})

Same thing for shutting down.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants