toAsync
toAsync() function
Returns AsyncIterable, toAsync
used when you want to handle Promise values inside Iterable.
declare function toAsync<T>(iter: Iterable<T | Promise<T>>): AsyncIterableIterator<T>;
Example
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]
);