-
Notifications
You must be signed in to change notification settings - Fork 0
Async For Each
Sykander edited this page Dec 13, 2019
·
8 revisions
/**
* Async For Each
* Loop over an iterable object asynchronously and resolve when all callbacks are resolved
* @async
* @param {Function} callback - callback(currentValue, index, array)
* @param {Object} [thisArg] - must be iterable
* @throws {TypeError}
*/
async function asyncForEach(callback, [thisArg]) {...}
const { asyncForEach } = require('iterable-async'),
array = [1, 2, 3];
asyncForEach(async element => {
console.log('Resolved element ' + element);
}, array);
// Resolved element 1
// Resolved element 2
// Resolved element 3
const { asyncForEach } = require('iterable-async'),
array = [1, 2, 3];
array.asyncForEach = asyncForEach;
array.asyncForEach(async element => {
console.log('Resolved element ' + element);
});
// Resolved element 1
// Resolved element 2
// Resolved element 3