Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagan-bansal/3f27bd1bd52a02263490e3ee9e1e9c66 to your computer and use it in GitHub Desktop.
Save gagan-bansal/3f27bd1bd52a02263490e3ee9e1e9c66 to your computer and use it in GitHub Desktop.
Process stream transform in parallel but output the data in parallel.
// example from parallel-transform
var transform = require('parallel-transform');
var stream = transform(5, function(data, callback) { // 5 is the parallism level
setTimeout(function() {
callback(null, data);
}, 1000);
});
for (var i = 0; i < 20; 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');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment