0

According to their documentation on series() and parallel() and their example, you only need to return a function call. However it doesn't work for me. This is my code:

import gulp from "gulp";

export const test = () => {
    return gulp.parallel(
        async () => console.log("Async done"),
        cb => { console.log("cb done"); cb(); },
    )(); // Without function call () nothing is run
};

// package.json gulp version:
{
  "devDependencies": {
    "gulp": "^4.0.2",
    // ...
  }
  // ...
}

The above code works fine, I can see the tasks being completed in the output. However, there's always a warning at the end:

The following tasks did not complete: test
Did you forget to signal async completion?

enter image description here

I have tried:

  • Do exactly like the example and return gulp.parallel() call without calling it. However in that case, nothing is executed and this answer helped: https://stackoverflow.com/a/39902796/653457

  • Remove either the async method or the cb method (so only a single task is executed). The warning still exists.

Is this a gulp's bug or did I do something wrong? I am new to Node and gulp.

I am not sure if this is related to the issue but I cannot use this like most documentation and examples:

import gulp, { series, parallel } from "gulp";

Named export 'parallel' not found. The requested module 'gulp' is a CommonJS module, which may not support all module.exports as named exports.


Update: for some reason, adding async to the function helps, I assume because Gulp now works on the Promise returned instead (you don't even need to use await on the parallel result, and it's not a Promise anyway):

export const test = async () => { // add async

Update 2:

Thanks to Mark comment, this also works but I have to wrap everything in another series, and technically test is done BEFORE the final task completes:

export const test = (cb) => {
    return gulp.series(
        gulp.parallel(
            async () => { await new Promise(r => setTimeout(r, 1000)); console.log("Async done") },
            cb => { console.log("cb done"); cb(); },
        ),
        async () => cb(), // This is done after test finish
    )();
}

// Output:
// ...
// [12:24:44] Finished 'test' after 1.01 s
// [12:24:44] Finished '<anonymous>' after 1.33 ms
Luke Vo
  • 17,859
  • 21
  • 105
  • 181
  • What happens if you use this: `export const test = (cb) => {` ? And then probably just call `cb()` without the arrow function. – Mark Jun 27 '23 at 21:51
  • @Mark yes that would work too, check the Update 2 I just added. Just curious why it's happening – Luke Vo Jun 28 '23 at 05:26

0 Answers0