slushjs / slush

The streaming scaffolding system - Gulp as a replacement for Yeoman
http://slushjs.github.io/generators
MIT License
1.24k stars 58 forks source link

.on('finish') fires before gulp-install concludes #20

Closed UltCombo closed 9 years ago

UltCombo commented 9 years ago

I believe the sample slushfile has an issue.

It currently listens to the finish event on the stream returned by gulp-install. As far as I can see, gulp-install returns a transform (through) stream, which is both a writable and readable stream. The finish event comes from the Writable stream, that is, it is fired as soon as buffers have finished being piped into the through stream.

I believe you'd rather wait until gulp-install's readable stream output ends (that is, when you call through2's flushFunction's callback).

I believe a valid fix would be:

.pipe(install())
.on('end', function() {
    // ... do stuff ...
    done(); // the gulp task's callback
})
.resume(); // Readable streams start and stay paused in Node >= 0.10 unless calling resume() 
           // or attaching a data listener
joakimbeng commented 9 years ago

Thanks!