@shigen/async-array
v0.1.0
Published
Wrapper around an `Iterable` or `AsyncIterable` providing the methods from the [Async Iterator Helpers proposal](https://github.com/tc39/proposal-async-iterator-helpers).
Readme
Async Array
Wrapper around an Iterable or AsyncIterable providing the methods from the Async Iterator Helpers proposal.
Usage
// callbacks don't run immediately
const squares = AsyncArray.from([1, 2, 3]).map(async (x) => {
console.log(x);
return x * x;
});
// callbacks are called once when the array is consumed with toSync or for await
console.log(await squares.toSync());
// 1
// 2
// 3
// [1, 4, 9]
// to prevent side effects, callbacks won't run again
console.log(await squares.toSync())
// [1, 4, 9]