Why do some Gulp threads "flow" by default, while others do not?

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();
    });
});

The launch gulp destbehaves 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, the launch gulp srconly outputs:

[12:31:11] Using gulpfile gulpfile.js
[12:31:11] Starting 'src'...

The callback is 'end'never called. After a bit of debugging, I think the thread in the task is dest flowing , while the thread in the source of the task is not.

Signaling a task srcfor an explicit thread by calling stream.resume():

gulp.task('src', function(done) {
  gulp.src('docs/*')
    .on('end', function() {
      console.log('ending');
      done();
    })
    .resume();
});

It gives the expected result:

[12:46:52] Using gulpfile gulpfile.js
[12:46:52] Starting 'src'...
ending
[12:46:52] Finished 'src' after 11 ms

I saw the same combination of behavior with plugins: gulp.dest and gulp-mocha seem to return the current threads, but gulp-logger and gulp-gh-pages do not.

Why is there a difference in behavior?

+3
2

, stream-end, :

end = require('stream-end')

gulp.task 'logger', (done) ->
  gulp.src 'docs/*'
    .pipe logger()
    .pipe end ->
      console.log('ending')
      done()

, , , .

+2

, , , , - .

gulp.src('docs/*') docs. end , .

, , , :

gulp.task('src', function(done) {
  gulp.src('docs/*')
    .on('data', function() {})
    .on('end', function() {
      console.log('ending');
      done();
    });
});

finish, ( ) , (.. ):

gulp.task('src', function(done) {
  gulp.src('docs/*')
    .on('finish', function() {
      console.log('ending');
      done();
    });
});

gulp gulp.dest('temp'), , end , .

+2

Source: https://habr.com/ru/post/1619257/


All Articles