Skip to content

Instantly share code, notes, and snippets.

@catdad
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catdad/1561f511b7f0d864cb4f to your computer and use it in GitHub Desktop.
Save catdad/1561f511b7f0d864cb4f to your computer and use it in GitHub Desktop.
Run multiple asynchronous tasks and stream tasks inside a single Gulp task
var gulp = require('gulp');
// a regular async function
function async(done) {
console.log('async start');
// take your time doing anything you want
setTimeout(function () {
console.log('async end');
done();
}, 500);
}
// create a task to do multiple things
gulp.task('multitask', function () {
// Get the target stream.
var target = gulp.dest('folder');
// Call your asynchronous method.
async(function () {
// Execute your regular pipe tasks here.
gulp.src('file.txt')
.pipe(target);
console.log('multitask is done');
});
// Return the target stream. This lets Gulp know this task is asynchronous,
// and it will wait for the stream to end before continuing.
return target;
});
gulp.task('test', ['multitask'], function () {
console.log('test is executing');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment