multirator
v0.1.0
Published
Async Iterator which supports multiple consumers
Downloads
3
Readme
multirator
Async Iterator which supports multiple consumers
Includes Array like functions for working with iterators (.filter(), .map(), .reduce(), .forEach() etc)
Install
npm i multirator
Usage
import Multirator from "multirator";
const numbers = new Multirator(someIterable); // 'someIterable' could be an async iterator, async generator or a stream
(async () => {
for await (number of numbers) {
console.log("Consumer 1", number);
}
})();
(async () => {
await numbers
.filter((number) => number % 2 !== 0)
.forEach((oddNumber) => console.log("Consumer 2", oddNumber));
})();
(async () => {
const total = await numbers.reduce((sum, number) => sum + number, 0);
console.log("Consumer 3", total);
})();