strom/samples/demo.js

24 lines
669 B
JavaScript
Raw Normal View History

2018-11-29 04:59:24 +00:00
const {
utils: { sleep, delay, once },
...Mhysa
} = require("mhysa");
async function main() {
2018-11-29 04:59:24 +00:00
const collector = Mhysa.concat(
Mhysa.fromArray(["a\n", "b\n", "c\n"]),
Mhysa.fromArray(["d", "e"]).pipe(Mhysa.join("-")),
)
.pipe(Mhysa.split("\n"))
.pipe(
2018-11-29 04:59:24 +00:00
Mhysa.flatMap(async s => {
await sleep(100);
return delay([s, s.toUpperCase()], 100);
}),
)
2018-11-29 04:59:24 +00:00
.pipe(Mhysa.collect({ objectMode: true }));
const collected = await once(collector, "data");
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 6 * 100 ms)
}
main();