1.0.0 • Published 5 years ago

promise-all-step v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

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()

ParamTypeDescription
collarrayA collection to iterate over
iterateefunctionAn async function to apply to each item in coll. Apply with (thisArg, item, index)
stepnumberAmount of ms that timeout increases after each item
thisArgobjectThe 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