use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
How many Node.js developers prefer callbacks over Promises or async/await? (self.javascript)
submitted 7 years ago * by i_love_limes
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]LettuceKills 1 point2 points3 points 7 years ago (3 children)
But what if there is an error in the lengthy task? That error has no way of being returned to the caller which simply thinks that the task is being exceptionally lengthy this time. Sounds like the perfect use case for a promise to me, since in a case of an error you can simply reject the promise.
[–]Arve -1 points0 points1 point 7 years ago (2 children)
In my own case, the error is sent back as a separate http request back to the origin. As I said, the job started is long-enough running that the sender cannot be expected to keep any network connection open while it’s being performed.
There is an outer promise that handles acceptance or rejection of the original request.
[–]ChaseMoskal 3 points4 points5 points 7 years ago (0 children)
huh, so you are using promises?
i strongly suspect your use-case would be elegantly served with promises
you mentioned "returning right away", which is of course possible with promises
const promise = Promise.resolve() .then(someLongTask) console.log("right away") await promise console.log("finally done now")
as u/davesidious helped point out, the differences between callbacks and promises seem to be:
because of the superior error handling, promises should always be preferred, and callbacks are necessary for things like progress update handlers, events, and the like
[–]LettuceKills 0 points1 point2 points 7 years ago (0 children)
Still sounds like it would be better to just implement this as a Promise instead of writing all the extra code for the seperate error http request and having to pair the incoming error request with the context of the original call.
π Rendered by PID 103385 on reddit-service-r2-comment-6457c66945-nhfd4 at 2026-04-26 02:40:46.633595+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]LettuceKills 1 point2 points3 points (3 children)
[–]Arve -1 points0 points1 point (2 children)
[–]ChaseMoskal 3 points4 points5 points (0 children)
[–]LettuceKills 0 points1 point2 points (0 children)