-
Notifications
You must be signed in to change notification settings - Fork 0
Async For Each
Sykander edited this page Feb 25, 2020
·
8 revisions
The asyncForEach() method executes a provided asynchronous function once for each array element.
asyncArr.asyncForEach(callback(currentValue[, index[, array]])[, thisArg])-
callbackAsync function to execute on each element. It accepts between one and three arguments:-
currentValueThe current element being processed in the iterable object. -
index|optionalThe index ofcurrentValuein the iterable object. -
array|optionalThe iterable object thatasyncFilterwas called upon.
-
-
thisArgoptionalValue to use asthiswhen executingcallback.
undefined
console.log('Starting update.');
const update = 'Important message!';
await AsyncArray.from(['foo.bar', 'baz.qux']).asyncForEach(async api => {
const { status, message } = await http.post(api, update);
console.log(api, status, message);
});
console.log('Done updating.');Starting Update.
foo.bar, 200, Updated
baz.qux, 200, Updated
Done updating.