Created
September 8, 2022 04:25
-
-
Save gagan-bansal/3f27bd1bd52a02263490e3ee9e1e9c66 to your computer and use it in GitHub Desktop.
Process stream transform in parallel but output the data in parallel.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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