UNPKG

batch-iterable

Version:

An abstraction to work with iterables of asyncIterables

16 lines (15 loc) 356 B
// @ts-check /** * @template T * @param {AsyncIterable<Iterable<T>>} iterable * @param {(item: T, index: number) => void} callback * @returns {Promise<void>} */ export default async function forEach(iterable, callback) { let index = 0 for await (const batch of iterable) { for (const item of batch) { callback(item, index++) } } }