question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gulp 4: gulp.parallel will stop gulp immediately when one task fails

See original GitHub issue

In the docs it is stated that gulp.parallel will still execute all tasks if an error occurs:

When the returned function is executed, the tasks or functions will be executed in parallel, all being executed at the same time. If an error occurs, all execution will complete.

This currently doesn’t seem to be the case as the following minimal code example will demonstrate:

var gulp = require('gulp')

gulp._settle = false

gulp.task('error', function(done) {
  setTimeout(function() {
    done(new Error('Somethings wrong!'))
  }, 200)
})

gulp.task('willnotfinish', function(done) {
  setTimeout(function() {
    console.log('I will never finish :(')
    done()
  }, 2000)
})

gulp.task('watch', function() {
  gulp.watch('watchme.js', gulp.parallel('default'))
})

gulp.task('default', gulp.parallel(
  'error',
  'willnotfinish'
))

This will stop running gulp after ~200ms with the following output and the task ‘willnotfinish’ will never finish executing:

Using gulpfile ~/Desktop/development/gulp-parallel-error/gulpfile.js
Starting 'default'...
Starting 'error'...
Starting 'willnotfinish'...
'error' errored after 204 ms
Error: Somethings wrong!
  at null._onTimeout (/Users/perplex/Desktop/development/gulp-parallel-error/gulpfile.js:5:10)
  at Timer.listOnTimeout (timers.js:92:15)
'default' errored after 211 ms
The following tasks did not complete: willnotfinish
Did you forget to signal async completion?

EDIT: Include watch task in code sample

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ulrichbcommented, Dec 17, 2018

The --continue switch is cool, but I would like to move this behavior change (of gulp.parallel()) into the gulpfile.js, and also scope it to a single parallel() sub-tree.

=> Any change to get this option into the API (e.g. gulp.parallel(..., { continue: true })?

An example use case is when executing linters in parallel: Then you don’t want to stop the execution if one linter emits errors (and you also want the output of all parallel executing linters). Also here you want to scope the --contine to just the linting-task (and not all the others).

0reactions
phatedcommented, Feb 23, 2019

@ulrichb it’s not something we want people to use but you can “hack the system” by setting gulp._settle = true before calling gulp.parallel (because gulp is just an instance of Undertaker and that’s the property undertaker looks for). You could also have a separate “settle” instance by doing:

var settled = new gulp.Gulp();
settled._settle = true;

settled.parallel(...tasks);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Async Completion - gulp.js
When composing tasks with parallel() , an error will end the composition but the other parallel tasks may or may not complete.
Read more >
Gulp error: The following tasks did not complete - Stack Overflow
I've seen a few example Gulp 4 examples such as this one where watchers don't seem to be accompanied by completion signals. What...
Read more >
How to use the gulp.on function in gulp - Snyk
How to use the gulp.on function in gulp. To help you get started, we've selected a few gulp examples, based on popular ways...
Read more >
The new task execution system - gulp.parallel and gulp.series
One of the major changes in Gulp 4 is the new task execution system. In this article, I want to show you what's...
Read more >
Getting Started with Gulp.js - Semaphore Tutorial
Gulp is a command-line task runner for Node.js. ... By the end of the tutorial, you will be able to apply Gulp to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found