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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
| Iterable<T, any, any> | Iterator<T, any, any> | AsyncIterable<T, any, any> | AsyncIterator<T, any, any> |
Returns
Section titled “Returns”AsyncGenerator<T>
Example
Section titled “Example”async function* source() { yield 1; yield 2;}
for await (const n of toAsyncIterable(source())) { // n: number}