Skip to content

toAsyncIterable

function toAsyncIterable<T>(source): AsyncGenerator<T>;

Defined in: to-async-iterable.ts:23

Convert an Iterable/Iterator/AsyncIterable/AsyncIterator into an AsyncIterable.

Useful for utilities that want to accept both sync and async sources.

Type Parameter
T
Parameter Type
source | Iterable<T, any, any> | Iterator<T, any, any> | AsyncIterable<T, any, any> | AsyncIterator<T, any, any>

AsyncGenerator<T>

async function* source() {
yield 1;
yield 2;
}
for await (const n of toAsyncIterable(source())) {
// n: number
}