Let\'s say I am using the following code to run a couple of promises in series:
let paramerterArr = [\'a\',\'b\',\'c\',\'d\',\'e\',\'f\']
parameterArr.reduce
The answers are good, but they wait too long since all the answers wait regardless of whether or not the actual operation took more than 50ms already.
You can use Promise.all for it.
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
let parameterArr = ['a','b','c','d','e','f'];
parameterArr.reduce(function(promise, item) {
return promise.then(function(result) {
return Promise.all([delay(50), myPromise(item)]);
});
}, Promise.resolve());