Multiple execution contexts for pull substreams.
npm install pull-substreampull-substream is a Through stream that creates a new instance of a given Through stream for each event. A substream
createThroughStream - a callback that creates a Through stream. This callback will get msg as an argument. msg is
contexts - The amount of parallel execution contexts. (Default=1).
pull-substream won't execute in paralel. The way it works is that it simply holds X amount of concurrent contexts. Each
pull-substream will pull the data from the next context in a round-robin fashion.
pull-substream.
js
var pull = require("pull-stream");
var flow = require("pull-flow");
var substream = require("pull-substream");
// Dummy async stream.
var asyncStream = pull.Through(function (read) {
return function (end, cb) {
read(end, function (end, data) {
if (end) return cb(end);
setTimeout( function () {
cb(end, data)
},Math.round(Math.random()*1000+1000));
});
}
})
pull(
pull.values([1,2,3,4,5,6]),
substream( function (msg) {
// msg is the event that is being dispatched
return pull(
asyncStream(),
asyncStream()
)
},2),
flow.parallel(2), // We'll execute those contexts in parallel
pull.drain(console.log)
)
`
install
With npm do:
`
npm install pull-substream
``