Implement Promise.series
See original GitHub issueWhen you have the list of values to be passed to the same function sequentially, so that the next call is only made only when the promise returned by the previous call is resolved, you either have to “manually” chain promises or use Promise.reduce, which both looks a bit ugly and also not so obvious.
It could be nice to have something like this:
Promise.series = function (arr, iteratorAsync) {
return Promise.reduce(arr, function(memo, item) {
return iteratorAsync(item);
}, 0);
}
Issue Analytics
- State:
- Created 10 years ago
- Comments:21 (4 by maintainers)
Top Results From Across the Web
Implementing Promise.series as alternative to Promise.all
If you truly want to run your promises in series, you should adjust your function and pass in an array of functions that...
Read more >Promise - JavaScript - MDN Web Docs
The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
Read more >How To Create Your Own Implementation Of JavaScript ...
How To Create Your Own Implementation Of JavaScript Promises. Watch later. Share. Copy link. Info. Shopping. Tap to unmute.
Read more >Implement Promise.all - Rajat Explains
This blog is about solving an interview question to implement Promise.all. ... This blog post is a part of the frontend interview series....
Read more >Implementing - Promises
Our goal here is to implement promise.done(onFulfilled, onRejected) such that: only one of onFulfilled or onRejected is called; it is only called once ......
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 Free
Top 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
Thank God I found this issue. I was under the impression that
Promise.all
was iterative. (I was.push
’ing promises onto an Array, expecting sequential execution).The reason for popularity of this suggestion is misunderstanding of promises and thinking of
Promise.all
as some kind of “parallel” which needs a sequential equivalent.But
Promise.all
doesn’t “parallelize” promises or anything, it does nothing to the input promises - it is simply just telling you whether the promises you already are controlling from somewhere else are completed or not.So because promises are not being controlled from the collection methods,
Promise.all
cannot have a.sequence
equivalent - aPromise.sequence
would always need a tailored “iteratorAsync
” function to go with it - just like reduce so no net savings of lines of code are gained .