Closed mo22 closed 9 years ago
in some scenarios, especially with gulp.src() resolving to an empty stream, merge2 misses the on('end') event.
The problem is solved by adding the on('end') immediately on addStream:
function addStream() { for (var i=0; i<arguments.length; i++) { (function(stream) { function onend() { stream.removeListener('merge2UnpipeEnd', onend); stream.removeListener('end', onend); console.log('stream ended', stream._id); if (stream._merge2_onend) { stream._merge2_onend(); } stream._merge2_finished = true; } stream.on('merge2UnpipeEnd', onend); stream.on('end', onend); })(arguments[i]); } ... function pipe(stream) { if (stream._merge2_finished) { console.log('pipe', stream._id, 'already finished'); next(); } else { console.log('pipe', stream._id, 'go'); stream._merge2_onend = function() { console.log('pipe', stream._id, 'end'); next(); } stream.pipe(mergedStream, {end: false}); } /* function onend() { stream.removeListener('merge2UnpipeEnd', onend); stream.removeListener('end', onend); next(); } stream.on('merge2UnpipeEnd', onend); stream.on('end', onend); stream.pipe(mergedStream, {end: false}); */ }
+1
found it that in my case it had a different issue and merge() work fine. sorry
@mo22 merge2 merge stream in sequence(one by one),I should pause streams waiting for pipe.
merge2
in some scenarios, especially with gulp.src() resolving to an empty stream, merge2 misses the on('end') event.
The problem is solved by adding the on('end') immediately on addStream: