-
-
Notifications
You must be signed in to change notification settings - Fork 174
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
Remove Promise around Listen #19
Comments
I think the new development is cool ! |
Sorry @Youngestdev, which do you mean? |
polka().listen(PORT, err => {
if (err) throw err; // or whatever you want to do
console.log(`> Ready on localhost:${PORT}`);
}); That looks cool |
Got it, thanks! |
@lukeed my 2c - I like the promise version more (since I've been using async/await a lot). |
Thanks @yamalight~! I'm still slightly in favor of removing the Promise version because I'm seeing a lot of early users trying to |
@lukeed how about allowing to do |
That's far more complicated and would use |
fair point 😃 |
I think we should remove the promise. I actually had some problems with. It took me a while to realise that This is also another step towards better express compatibility like #29 ... and less code! What's not to like. |
Changing to something like listen(...args) {
(this.server = this.server || http.createServer()).on('request', this.handler);
this.server.listen(...args);
return this.server;
} would be closer to honouring options for net.Server |
Yup! That's actually exactly the code I was going to write. I just (still) haven't decided if this should happen or not. Pros & cons for each side. |
Yeah. And I think promisification can be done by // sketchy, untested code ahead
const {promisify} = require('util');
const app = require('polka')();
app.use((req, res) => {
res.end(200, 'OK');
});
const start = promisify(app.server.listen); // assuming server already exists
start()
.then(...)
.catch(err => ...); (😜) |
now i was start node index.js and i get ---- attempt to reconnect has failed--- in browser how can i do sir ? |
How about exposing a promise as a server property? const server = polka().listen(PORT)
server.started.then(f).catch(e) |
This seemed like a good initially just because of
then/catch
, but there are a few problems with this:Calling
.listen()
does not return the Polka instance directly, so it forceslisten
to always be called last.It also prevents one-line initializers for a server.
The top-level
then
andcatch
blocks make it seem likecatch
is the global catch-all handler.Instead,
.listen()
would expose the underlyingserver.listen
method directly, meaning that signature is the same as all other servers.This would also remove 5 lines of code 😆
The text was updated successfully, but these errors were encountered: