Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 1x 1x 7x 6x 5x 1x | const { mapIterable } = require('./helpers'),
{ validateIsIterable, validateIsFunction } = require('./validation');
/**
* Async For Each
*
* Loop asynchronously and resolve when all callbacks are resolved
* @async
* @param {any[]} iterable
* @param {Function} callback - callback(currentValue, index, array)
* @param {any} [thisArg=undefined]
* @return {Promise<void>}
* @throws {TypeError}
*/
async function asyncForEach(iterable, callback, thisArg = undefined) {
validateIsIterable(iterable);
validateIsFunction(callback);
await Promise.all(
mapIterable(iterable, callback.bind(thisArg), {
useEmptyElements: false
})
);
}
module.exports = { asyncForEach };
|