You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
904 B
JavaScript
44 lines
904 B
JavaScript
"use strict";
|
|
|
|
const pipe = require("@promistream/pipe");
|
|
const debug = require("@promistream/debug");
|
|
const fromIterable = require("@promistream/from-iterable");
|
|
const forkSelect = require("./");
|
|
const collect = require("@promistream/collect");
|
|
|
|
(async () => {
|
|
let [ a, b ] = await pipe([
|
|
fromIterable([ 0, 0, 0, 1, 1, 2 ]),
|
|
debug("source"),
|
|
forkSelect(2, (value) => {
|
|
return value % 2;
|
|
})
|
|
]).read();
|
|
|
|
setTimeout(async () => {
|
|
try {
|
|
let bResults = await pipe([
|
|
b,
|
|
// debug("pipeline B"),
|
|
collect()
|
|
]).read();
|
|
|
|
console.log({ bResults }); // { bResults: [ 1, 1 ] }
|
|
} catch (error) {
|
|
console.error("error from B", error);
|
|
}
|
|
}, 1000);
|
|
|
|
try {
|
|
let aResults = await pipe([
|
|
a,
|
|
// debug("pipeline A"),
|
|
collect()
|
|
]).read();
|
|
|
|
console.log({ aResults }); // { aResults: [ 0, 0, 0, 2 ] }
|
|
} catch (error) {
|
|
console.error("error from A", error);
|
|
}
|
|
})();
|