grncdr / merge-stream

Merge multiple streams into one interleaved stream
MIT License
214 stars 16 forks source link

merge does not end... #12

Closed AlimovSV closed 9 years ago

AlimovSV commented 10 years ago

When source stream throw error but has .on('error', function() {}) merged streams never end.

UltCombo commented 10 years ago

I can't reproduce it here, the merged stream emits end just fine after handling source streams' errors.

shinnn commented 9 years ago

@AlimovSV

Could you show us an example code to reproduce the error you ran into, and the error messages?

grncdr commented 9 years ago

Closing issue as I also can't reproduce this.

grncdr commented 9 years ago

Please re-open if the issue re-occurs.

UltCombo commented 9 years ago

Possibly related: wearefractal/vinyl-fs#51

grncdr commented 9 years ago

That sounds more like https://github.com/grncdr/merge-stream/issues/14 which was just fixed.

UltCombo commented 9 years ago

Oh nice, thanks!

grncdr commented 9 years ago

Don't thank me, @fixplz pointed me right at the problem :+1:

elisechant commented 9 years ago

I am facing a similar issue

UltCombo commented 9 years ago

@elisechant make sure all of your merged streams are actually emitting an end event. This issue usually happens when one or more of the merged streams don't actually end.

elisechant commented 9 years ago

@UltCombo How might I emit an end event?

var gulp        = require('gulp');
var mergeStream = require('merge-stream');
var del         = require('del');

gulp.task('script', function() {
    var merged = mergeStream();

    merged.add(
        gulp.src('src/one.js')
            .on('end', function() { console.log('END MERGE'); })
            .pipe(gulp.dest( 'dest' ))
    );

    return merged;
});

gulp.task('clean', function(cb) {
    del([
        'dest'
    ], cb);
});
  1. run gulp script, prints 'END MERGE'
  2. run gulp clean, prints 'END MERGE'
  3. run gulp clean, prints 'END MERGE'
  4. etc
UltCombo commented 9 years ago

That's odd, it looks like your gulpfile is okay. What's the issue you're experiencing?

elisechant commented 9 years ago

@UltCombo my issue is that repeated calls to gulp clean after executing gulp script print END MERGE for ever more. My expectation is that the should have ended. Is there a workaround to stop the stream inside the task (unpipe?)? something like:

gulp.task('script', function() {
    var merged = mergeStream();

    merged.add(
        gulp.src('src/one.js')
            .on('end', function() { console.log('END MERGE'); })
            .pipe(gulp.dest( 'dest' ))
    );

    // pseudo code
    merged.process();
    merged.end();
});
UltCombo commented 9 years ago

Sorry, I didn't quite understand. It looks like your simplified sample code is missing some key parts. It would be nice if you could describe what you're trying to achieve, post enough of your gulpfile to reproduce the issue and describe what's not going well. Perhaps this topic would be better fit for Stack Overflow.

elisechant commented 9 years ago

Thanks @UltCombo. For the thread, to kill the process so it doesn't hang around after execution, this seems to be an ok workaround:

stream.add(
    gulp.src('src/one.js')
        .on('end', function() {
            this.emit( 'unpipe' );  // remove the finished task from the stream
        })
        .pipe(gulp.dest( 'dest' ))
);
grncdr commented 9 years ago

@elisechant could you please include a gulpfile that demonstrates the problem? The one you included above works fine for me.