Last active
August 29, 2015 14:21
-
-
Save catdad/1561f511b7f0d864cb4f to your computer and use it in GitHub Desktop.
Run multiple asynchronous tasks and stream tasks inside a single Gulp task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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