Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
2 folders · 6 files
README.md
module-async-iter #
Async iterable helpers.
Helpers #
mapIterableAsync({ fn, iterable }): maps each item of a sync or async iterable through an asyncfn, collecting the results into an array in input order.
Behavior #
mapIterableAsync is an eager collect-to-array mapper,
not a lazy async-iterator transform.
It does not yield
values one at a time;
it starts every fn call during iteration,
then joins them with a single Promise.all.
- Eager:
each
fncall begins immediately, before any result is awaited, so the mapper calls overlap. - Unbounded concurrency: there is no cap; if the iterable has 10000 items, 10000 mapper calls start at once.
- Order preserving: results land in input order, regardless of which mapper resolves first.
- Rejection:
a rejected mapper rejects the returned promise,
following
Promise.allsemantics.
For bounded concurrency,
wrap the mapper with a limiter such as p-limit;
this package intentionally does not.
Usage #
import { mapIterableAsync, } from '@monochromatic-dev/module-async-iter';
const sizes = await mapIterableAsync({
fn: async (url,) => (await fetch(url,)).headers.get('content-length',),
iterable: ['/a', '/b', '/c',],
},);
Both sync and async iterables are accepted:
async function* lines() {
yield 'first';
yield 'second';
}
const upper = await mapIterableAsync({
fn: async (line,) => line.toUpperCase(),
iterable: lines(),
},);