Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should app.listen also return a promise? #45

Closed
blai opened this issue Sep 1, 2013 · 5 comments
Closed

Should app.listen also return a promise? #45

blai opened this issue Sep 1, 2013 · 5 comments

Comments

@blai
Copy link

blai commented Sep 1, 2013

https://github.com/koajs/koa/blob/master/lib/application.js#L62 currently returning server.listen(), thoughts?

@jonathanong
Copy link
Member

What would that accomplish?

@blai
Copy link
Author

blai commented Sep 1, 2013

well, in Node.js server.listen() also take a callback, with the first argument being error. There has not been an easy way to doing something like: wait for the server to start listening (some app might take a bit to instantiate all the middleware dependencies, e.g. a db connection). Or something like, if the server failed to start listening because the port is in use, try start in a different port. I guess this (returning promise) opens up some possibilities, just a random thought.

@tj
Copy link
Member

tj commented Sep 1, 2013

I'd like to defer that sort of boot logic, ideally you'd get everything ready and then .listen() for connections, but thankfully most database drivers buffer requests and so on so usually .listen() at the bottom without a callback is just fine

@tj tj closed this as completed Sep 1, 2013
@jonathanong
Copy link
Member

@visionmedia why not just remove app.listen()? people are inevitably going to ask for more like with Express. ie i wanted expect: 100-continue support, but it's easier just to create the server myself. you use http.createServer(app.callback()) in half your tests and examples anyways.

@tj
Copy link
Member

tj commented Sep 1, 2013

I find it useful, just need to be certain that it's not going to change and turn into some giant wtf

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

No branches or pull requests

3 participants