3

Suppose I have the following task:

gulp.task('my-task', function (cb) {
    fs.appendFileSync('myPath', 'data');
});

When I do something like this:

gulp.task('build', function (cb) {
    runSequence('my-task', 'some-task',cb);
});

my-task runs and finishes, but some-task never runs.

My question is: how do I make some-task run after my-task has finished?

Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
philomath
  • 2,209
  • 6
  • 33
  • 45

1 Answers1

1

Your problem is that gulp doesn't notice that my-task has finished. When you declare a callback function cb you have to actually call the callback:

gulp.task('my-task', function (cb) {
  fs.appendFileSync('myPath', 'data');
  cb();
});

Or you can leave the callback out entirely, since fs.appendFileSync is synchronous anyway:

gulp.task('my-task', function () {
  fs.appendFileSync('myPath', 'data');
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
  • Thanks for the nice trick of leaving the callback out entirely. So what's the logic behind this? can you point me to some documentation? – philomath May 11 '16 at 09:20
  • Tasks are always synchronous unless you use [one of the three ways of hinting asynchronous behaviour](https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support) – Sven Schoenung May 11 '16 at 09:31