Package Exports
- async-iter-utils
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (async-iter-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
async-iter-utils
Useful utilities for js async iterators.
Install
npm install async-iter-utils
# OR
yarn add async-iter-utilsDocs
onItem(iterable, fn)
convert an async iterator to callback style
const {onItem} = require('async-iter-utils');
onItem(iterable, (item) => {
console.log(item);
})forEach(iterable, fn, {concurrency = 1, stopOnError = true} = {})
Run a function for each item of async iterable with given concurrency. If stopOnError is false, all errors will be collected and returned as an AggregateError, otherwise it'll stop on any error.
const {forEach} = require('async-iter-utils');
await forEach(iterable, async (item) => {
console.log(await process(item));
}, {concurrency: 10});map(iterable, fn, {concurrency = 1, stopOnError = true} = {})
Same as forEach but will collect and return all results as an array.
const {forEach} = require('async-iter-utils');
const results = await map(iterable, async (item) => {
return process(item);
}, {concurrency: 10});toArray(iterable, {concurrency = 1} = {})
Convert an async iterable to an array.
const {toArray} = require('async-iter-utils');
const arr = await toArray(iterable);chunk(iterable, {chunkSize = 1} = {})
Convert an async iterable to another async iterable of chunkSize.
const {chunk} = require('async-iter-utils');
const chunkedIterator = chunk(iterable, {chunkSize: 10});
for await (const chunks of chunkedIterator) {
await Promise.all(chunks);
}