through2-parallel
v0.1.3
Published
Parallel Transform stream with an interface lifted from through2
Downloads
372
Maintainers
Readme
through2-parallel
Creates a through stream (Transform stream) which executes in parallel while maintaining the order of the emitted chunks.
Stability: Experimental
Usage
var throughParallel = require('through2-parallel');
var stream = throughParallel.obj(function(chunk, enc, cb) {
var self = this;
setTimeout(function() {
console.log("Completed " + chunk.order);
self.push(chunk.order);
cb();
}, chunk.time);
console.log("Started " + chunk.order);
});
stream.on('data', function(chunk) {
console.log("Emitted: " + chunk);
});
stream.write({time: 500, order: 1});
stream.write({time: 200, order: 2});
stream.write({time: 100, order: 3});
stream.end();The code above will print (default concurrency is 2):
Started 1
Started 2
Completed 2
Completed 1
Emitted: 1
Emitted: 2
Started 3
Completed 3
Emitted: 3API
throughParallel([options], [transform], [flush])
options: Options to pass to theTransformstream plus one specific option:concurrency: defaults to2and specifies how many tasks can run in parallel
transform: the_transformfunction.flush: the_flushfunction.
throughParallel.obj([options], [transform], [flush])
A syntactic sugar for throughParallel({objectMode: true}, ...).




