Remove every() method (redundant with async.io) and rework demo sample
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { sleep, once, delay, every, stream } = require("mhysa");
|
||||
const { sleep, once, delay, stream } = require("mhysa");
|
||||
|
||||
async function main() {
|
||||
const collector = stream
|
||||
@@ -7,19 +7,15 @@ async function main() {
|
||||
stream.fromArray(["d", "e"]).pipe(stream.join("-")),
|
||||
)
|
||||
.pipe(stream.split("\n"))
|
||||
.pipe(stream.flatMap(s => [s, s.toUpperCase()]))
|
||||
.pipe(
|
||||
stream.flatMap(async s => {
|
||||
await sleep(100);
|
||||
return delay([s, s.toUpperCase()], 100);
|
||||
}),
|
||||
)
|
||||
.pipe(stream.collect({ objectMode: true }));
|
||||
|
||||
const collected = await once(collector, "data");
|
||||
await sleep(1000); // undefined (after one second)
|
||||
console.log(await delay(collected, 1000)); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after another second)
|
||||
await every(
|
||||
[Promise.resolve("ab"), delay("cd", 1000)],
|
||||
s => s.length === 2,
|
||||
); // true (after another second)
|
||||
await every(
|
||||
[Promise.resolve("ab"), delay("cd", 1000)],
|
||||
s => s.length === 1,
|
||||
); // false (instantly)
|
||||
console.log(collected); // [ 'a', 'A', 'b', 'B', 'c', 'C', 'd-e', 'D-E' ] (after 6 * 100 ms)
|
||||
}
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user