gulp-tap icon indicating copy to clipboard operation
gulp-tap copied to clipboard

Async onEnd doesn't run when called after tap

Open flekschas opened this issue 7 years ago • 5 comments

When I specify .on('end', callback) after calling tap the event callback will not be fired. One can get around this by specifying the event callback first but I am wondering if this is expected or a bug?

gulp.task('test', function() {
    return gulp.src(paths.css)
        .pipe(doSomething())
        .on('end', tap(function() {
            // this will be executed
            console.log('Tasks done (A)')
        }))
        .pipe(tap(function(file) {
            console.log(file);
        }))
        .on('end', tap(function() {
            // this will not be executed
            console.log('Tasks done (B)')
        }))
});

flekschas avatar Aug 13 '17 18:08 flekschas

bump

timc13 avatar Feb 20 '18 23:02 timc13

It works for me with simple

gulp.task('test', () =>
  gulp.src(…).pipe(…).on('end')
)

but not with

gulp.task('test', (cb) =>
  gulp.src(…).pipe(…).on('end', cb)
)

Kagami avatar Mar 20 '18 15:03 Kagami

Sorry - don't have time to look into this at the moment. Perhaps @Javey, @mgutz, @revelt or @isiahmeadows could take a look if you have some spare time?

dotnetCarpenter avatar Mar 20 '18 16:03 dotnetCarpenter

If only the code was decaffeinated...

revelt avatar Mar 20 '18 17:03 revelt

Hi @flekschas . Firstly the callback for end event must be a function, so you should not use tap which return a stream to bind. It works for me like bellow.

gulp.task('test', function() {
    return gulp.src('./*.js')
        .on('end', function() {
            console.log(1);
        })
        .pipe(tap(function(file) {
            console.log(file)
        }))
        .on('end', function() {
            console.log(2);
        });
});

Javey avatar Mar 21 '18 07:03 Javey