Consider these two gulp tasks:
gulp.task('src', function(done) {
gulp.src('docs/*')
.on('end', function() {
console.log('ending');
done();
});
});
gulp.task('dest', function(done) {
gulp.src('docs/*')
.pipe(gulp.dest('temp'))
.on('end', function() {
console.log('ending');
done();
});
});
Running gulp dest
behaves as expected, outputting:
[12:33:15] Using gulpfile ~/Projects/gulp-exit/gulpfile.js
[12:33:15] Starting 'dest'...
ending
[12:33:15] Finished 'dest' after 13 ms
However, running gulp src
only outputs:
[12:31:11] Using gulpfile gulpfile.js
[12:31:11] Starting 'src'...
The 'end'
callback is never called. After a bit of debugging, I think the stream in the dest
task is flowing while the stream in the source task is not.
Signaling the src
task to flow explicitly by calling stream.resume()
:
gulp.task('src', function(done) {
gulp.src('docs/*')
.on('end', function() {
console.log('ending');
done();
})
.resume();
});
Gives the expected output:
[12:46:52] Using gulpfile gulpfile.js
[12:46:52] Starting 'src'...
ending
[12:46:52] Finished 'src' after 11 ms
I've seen this same mix of behaviors with plugins: gulp.dest and gulp-mocha seem to return flowing streams while gulp-logger and gulp-gh-pages do not.
Why the difference in behavior?