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.
32 lines
918 B
JavaScript
32 lines
918 B
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
|
|
const derivedStream = require("./");
|
|
const pipe = require("@promistream/pipe");
|
|
const collect = require("@promistream/collect");
|
|
const rangeNumbers = require("@promistream/range-numbers");
|
|
|
|
return Promise.try(() => {
|
|
let producedStream = pipe([
|
|
rangeNumbers(0, 10),
|
|
derivedStream((source) => {
|
|
/* NOTE: This example doesn't actually do anything *useful*. It
|
|
only demonstrates the higher-order stream mechanism.
|
|
Real-world code implementing eg. load-balanced stream forks
|
|
would probably do something like producing an array of multiple
|
|
streams here (instead of a single pipeline), and do some
|
|
internal routing of source values across them. */
|
|
|
|
return pipe([
|
|
source,
|
|
collect()
|
|
]);
|
|
})
|
|
]).read();
|
|
|
|
return producedStream.read();
|
|
}).then((result) => {
|
|
console.log(result); // [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
|
|
});
|