Reputation: 2565
I have an Array of gulp task:
var tasks = ['task1','task2','task3'];
if i start my following gulp task, it will run all tasks in my tasks array, but at the same time.
gulp.start('mytasks', tasks, function(){});
Is there a way to run my tasks from the tasks array asynchronously ?
Upvotes: 1
Views: 931
Reputation: 6286
Gulp is promise based and by default asynchronous . Quoting from the official Gulp documentation:
Tasks can be made asynchronous if its fn does one of the following:
- Return a stream
- Return a promise
- Accept a callback
Take a look at this example which emulates the behaviour mentioned above.
var gulp = require('gulp'),
wait = require('gulp-wait');
var tasks = ["task1","task2","task3"]
gulp.task('mytasks', function() {
return gulp.src("/dist")
.pipe(wait(5))
.pipe(gulp.dest('DESTINATIONPATH'));
});
gulp.task('task1', function() {
return gulp.src("/dist")
.pipe(wait(100))
.pipe(gulp.dest('DESTINATIONPATH'));
});
gulp.task('task2', function() {
return gulp.src("/dist")
.pipe(wait(200))
.pipe(gulp.dest('DESTINATIONPATH'));
});
gulp.task('task3', function() {
return gulp.src("/dist")
.pipe(wait(50))
.pipe(gulp.dest('DESTINATIONPATH'));
});
gulp.task('default', function() {
gulp.start('mytasks', tasks, function(){});
});
Upvotes: 1