grncdr / merge-stream

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

Objects not flushed on end #14

Closed fixplz closed 9 years ago

fixplz commented 9 years ago

I encountered a bug when using merge-stream with Gulp @3.8.10

Doing mergeStream(...).pipe(gulp.dest(...)) does not flush the objects buffered in mergeStream when the stream ends.

It looks like output.emit('end') should be .end().

Pls fix.

var gulp = require('gulp')
var Vinyl = require('vinyl')
var through2 = require('through2')
var tap = require('gulp-tap')
var merge = require('merge-stream')

gulp.task('default', function() {
    var num = 0
    return (
        merge(src(20))
        .on('end', function() { console.log('end merge') })
        .pipe(tap(function(thing) { console.log('got 1', thing.path) }))
        .pipe(gulp.dest('./foo'))
        .pipe(tap(function(thing) { console.log('got 2', thing.path) }))
        .pipe(tap(function(thing) { num++; console.log(thing) }))
        .on('end', function() {
            console.log('!!!', 'end', num)
        })
    )
})

function src(count) {
    var stream = through2.obj()
    setTimeout(function() {
        for(var i = 0; i < count; i++)
            stream.write(new Vinyl({path: './file' + i, contents: new Buffer('beepboop')}))
        stream.end()
    })
    return stream
}
~/Desktop/wat% node -v
v0.10.32

~/Desktop/wat% npm ls --depth=0
wat@1.0.0 /Users/G/Desktop/wat
├── gulp@3.8.10
├── gulp-tap@0.1.3
├── merge-stream@0.1.6
├── through2@0.6.3
└── vinyl@0.4.6
grncdr commented 9 years ago

Released in 0.1.7