Remove Promise around Listen
See original GitHub issueThis 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.
const server = polka().listen(3000); //=> server is Promise, not Polka instance
-
The top-level
then
andcatch
blocks make it seem likecatch
is the global catch-all handler.
Instead, .listen()
would expose the underlying server.listen
method directly, meaning that signature is the same as all other servers.
polka().listen(PORT, err => {
if (err) throw err; // or whatever you want to do
console.log(`> Ready on localhost:${PORT}`);
});
This would also remove 5 lines of code 😆
Issue Analytics
- State:
- Created 6 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
resolving a promise with EventListener - Stack Overflow
I have tried and although I can resolve the promise, I cannot remove the event handler. What would be a different solution here?...
Read more >Using promises - JavaScript - MDN Web Docs
A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of ...
Read more >Error handling with promises
When a promise rejects, the control jumps to the closest rejection handler down ... executor and promise handlers has an "invisible try..catch "...
Read more >How to cancel a promise in javascript ? - DEV Community
Promise cannot be cancelled, it is the process that returns promise must be cancellable. For example, XmlHttpRequest is cancellable as it has an ......
Read more >How to make a Promise out of a Callback function in JavaScript
In the code above, I put the callback-based request function inside a Promise wrapper Promise( (resolve, reject) => { //callback function}) . ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That looks cool
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.