Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Finish task when all task, running in parallel, are finished. #333

@sjoerdvisscher

Description

@sjoerdvisscher

I want a taks to run 2 subtasks in parallel, and finish when they are both finished.

I was hoping that I could use the callback argument on gulp.start like this:

gulp.task('one', function(cb) {
    console.log('one')
    setTimeout(cb, 100)
})

gulp.task('two', function(cb) {
    console.log('two')
    setTimeout(cb, 200)
})

gulp.task('default', function(cb) {
    gulp.start('one', 'two', function() {
        console.log('gulp.start callback');
        cb()
    })
})

But the gulp.start callback is never called. Gulp quits immediately after task 'two' is done, and the default task never finishes. When I change the default task to

gulp.task('default', function(cb) {
    gulp.start('one', 'two', function() {
        console.log('gulp.start callback');
    })
    cb()
})

then the default task finishes right after starting both subtasks as expected. But then the gulp.start callback is executed after both subtasks are finished.

As another test I also tried

gulp.task('default', function() {
    gulp.start('one', 'two', function() {
        gulp.start('one', 'two')
    })
})

This causes the subtasks to repeatedly be run, in other words, the inner gulp.start reuses the callback of the outer gulp.start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions