Skip to content

toAsync() function

Returns AsyncIterable, toAsync used when you want to handle Promise values inside Iterable.

Signature:

typescript
declare function toAsync<T>(iter: Iterable<T | Promise<T>>): AsyncIterableIterator<T>;

Example

ts
let acc = 0;
for await (const item of toAsync([1, 2, 3, 4, 5])) {
  acc += item;
}
// acc: 15

// with pipe
await pipe(
 [Promise.resolve(1),Promise.resolve(2),Promise.resolve(3)],
 toAsync,
 map(a => a + 10),
 toArray, // [11, 12, 13]
);

Try It

see pipe, toAsync, toArray

Open Source Code

Released under the Apache-2.0 License.