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.

57 lines
1.0 KiB
JavaScript

"use strict";
const Promise = require("bluebird");
const pipe = require("@promistream/pipe");
const map = require("@promistream/map");
const collect = require("@promistream/collect");
const fromIterable = require("@promistream/from-iterable");
const forkFilter = require("./");
return Promise.try(() => {
let [ streamA, streamB ] = pipe([
fromIterable([ 0, 1, 3, 4, 6, 8, 9, 10, 11, 13, 15, 16 ]),
forkFilter(2, (value) => value % 2)
]).read();
return Promise.all([
pipe([
streamA,
map((string) => `[stream A] ${string}`),
collect()
]).read(),
pipe([
streamB,
map((string) => {
return Promise
.resolve(`[stream B] ${string}`)
.delay(20); // Emulate some slow processing step
}),
collect()
]).read(),
]);
}).then((results) => {
console.log(results);
/*
[
[
'[stream A] 0',
'[stream A] 4',
'[stream A] 6',
'[stream A] 8',
'[stream A] 10',
'[stream A] 16'
],
[
'[stream B] 1',
'[stream B] 3',
'[stream B] 9',
'[stream B] 11',
'[stream B] 13',
'[stream B] 15'
]
]
*/
});