@piglovesyou/parallel-transform
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

@piglovesyou/parallel-transform

This is a maintained version of parallel-transform which includes:

  • TypeScript Definition (with purely rewritten in TypeScript implementation)
  • Fix mafintosh/parallel-transform#4 ; It works well in require('stream').pipeline

parallel-transform

Transform stream for Node.js that allows you to run your transforms in parallel without changing the order of the output.

npm install parallel-transform

It is easy to use

var transform = require('parallel-transform');

var stream = transform(10, function(data, callback) { // 10 is the parallism level
	setTimeout(function() {
		callback(null, data);
	}, Math.random() * 1000);
});

for (var i = 0; i < 10; i++) {
	stream.write(''+i);
}
stream.end();

stream.on('data', function(data) {
	console.log(data); // prints 0,1,2,...
});
stream.on('end', function() {
	console.log('stream has ended');
});

If you run the above example you'll notice that it runs in parallel (does not take ~1 second between each print) and that the order is preserved

Stream options

All transforms are Node 0.10 streams. Per default they are created with the options {objectMode:true}. If you want to use your own stream options pass them as the second parameter

var stream = transform(10, {objectMode:false}, function(data, callback) {
	// data is now a buffer
	callback(null, data);
});

fs.createReadStream('filename').pipe(stream).pipe(process.stdout);

Unordered

Passing the option {ordered:false} will output the data as soon as it's processed by a transform, without waiting to respect the order.

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.2
    443
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.1.2
    443
  • 2.1.1
    0
  • 2.1.0
    0
  • 2.0.0
    0

Package Sidebar

Install

npm i @piglovesyou/parallel-transform

Weekly Downloads

443

Version

2.1.2

License

MIT

Unpacked Size

9.39 kB

Total Files

5

Last publish

Collaborators

  • piglovesyou