promise-all-step
v1.0.0
Published
Like Promise.all(), but execute each task after a timeout which increase by step.
Readme
PromiseAllStep(coll, iteratee, step, thisArg) ⇒ Promise
Applies the function iteratee to each item in coll after a timeout, which's increased by a step.
Returns: Promise - Like the result of Promise.all()
| Param | Type | Description | | --- | --- | --- | | coll | array | A collection to iterate over | | iteratee | function | An async function to apply to each item in coll. Apply with (thisArg, item, index) | | step | number | Amount of ms that timeout increases after each item | | thisArg | object | The iteratee context |
Example
let words = ['Promise', 'all', 'step'];
PromiseAllStep(words, async (word, index) => {
let uppercase_word = word.toUpperCase();
console.log(`${word} => ${uppercase_word}`);
return uppercase_word;
}, 1000)
.then(uppercase_words => console.log('All upper case words : ', uppercase_words.join(', ')))
.catch(err => console.log(err));
// Will print :
Promise => PROMISE // at 0ms
all => ALL // at 1000ms
step => STEP // at 2000ms
All upper case words : PROMISE, ALL, STEP // at 2000ms