Run fn on each element of arr, one at a time, and give back a sequentially ordered list of results.
// do something like `throw new Error('break');` to stop
Promise._map = async function (arr, fn) {
let results = [];
await arr.reduce(async function (promise, el, i) {
await promise;
let result = await fn(el, i, arr);
results.push(result);
}, Promise.resolve());
return results;
};
Promise._sleep(n)
Proimse._map(arr, fn)
Proimse._parallel(n, arr, fn)
Run
fn
on each element ofarr
, one at a time, and give back a sequentially ordered list of results.