-
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])
-
callback
Async function to execute on each element. It accepts between one and three arguments:-
currentValue
The current element being processed in the iterable object. -
index
|optional
The index ofcurrentValue
in the iterable object. -
array
|optional
The iterable object thatasyncFilter
was called upon.
-
-
thisArg
optional
Value to use asthis
when 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.