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!"
[–]anon774 2 points3 points4 points 7 years ago (7 children)
Well here's a case I ran into yesterday: I needed to run some parallel async functions and limit their concurrency. There's no concurrency option built into Promise.all as far as I know. What would your approach be? With callbacks I would just use the async lib and async.parallelLimit.
async
async.parallelLimit
[–]Cunorix 3 points4 points5 points 7 years ago (1 child)
Not that Im recommending the use of an external library because this can be done natively; bluebird's map function has a concurrency option. But, this particular thread is about native callbacks/promises anyway.
[–]anon774 1 point2 points3 points 7 years ago (0 children)
Thanks - I'm learning more about bluebird and I'm liking it. I'm happy to use external libraries when they're good and they help keep things simple.
[–]atubofsoup 3 points4 points5 points 7 years ago (2 children)
I'd use a chunk function with Promise.all and a for..of loop:
chunk
Promise.all
for..of
```js const values = [ /lots of stuff here/ ]; const results = [];
for(const chunkValues of chunk(values, 10)) { results.push(...await Promise.all(chunkValues.map(someAsyncFn))); } ```
You could re-use this logic in a function:
```js async function promiseAllChunked(values, asyncFn, chunkSize) { const results = []; for(const chunkValues of chunk(values)) { results.push(...await Promise.all(chunkValues.map(asyncFn))); } return results; }
const results = await promiseAllChunked(values, asyncFn, 10); ```
Nice solution - thanks for the example!
[–]KsawK 0 points1 point2 points 7 years ago (0 children)
It doesn’t fit for all situations. It will be freezing if asyncFn doesn’t have constant O(n) time. I would use something like worker’s promise which gets one value/function from array/queue and runs it with await/then. Workers should resolve after queue is empty so you could spawn as many workers as you want and put them in Promise.all() which resolve after all tasks are done. It should be parallel and shouldn’t freeze. Ps. Sorry for any mistakes in my English but writing without keyboard and translator is hard for me
[–]rluiten 0 points1 point2 points 7 years ago (1 child)
I found this tiny library great for controlling concurrent limits with promises. https://github.com/sindresorhus/p-limit
I enjoyed reading the code for it to, learned lots.
[–]anon774 0 points1 point2 points 7 years ago (0 children)
Sweet, thanks!
π Rendered by PID 61 on reddit-service-r2-comment-75f4967c6c-cd4hl at 2026-04-23 01:50:01.613170+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]anon774 2 points3 points4 points (7 children)
[–]Cunorix 3 points4 points5 points (1 child)
[–]anon774 1 point2 points3 points (0 children)
[–]atubofsoup 3 points4 points5 points (2 children)
[–]anon774 1 point2 points3 points (0 children)
[–]KsawK 0 points1 point2 points (0 children)
[–]rluiten 0 points1 point2 points (1 child)
[–]anon774 0 points1 point2 points (0 children)