How can I avoid using a recursion like structure when I got several streams to open and I have to get an absolute end
event to finish the logic.
var someArray = ['file1', 'file2', 'file3'];
someArray.forEach(function( file ) {
fs
.createReadStream( file )
.pipe( /* do some stuff */ )
.on('data', function( usageInfo ) {
// done?
});
}
I got several files I have to pipe through tp some processes. How can I setup an event that tells me when all of them are done?
Currently what I'm getting is each end
event individually.
I can absolutely start each stream at the same time. I just need to somehow collect the end?
I could invoke a function call for each end
event and count it... that sounds hacky though?...
I feel like there is a way to do this with promises but I don't know how.
See Question&Answers more detail:os