Sunday, 19 October 2014

Handling Sync Tasks with Gulp JS


Handling Sync Tasks with Gulp JS (Russian re post here)
 - good post with example using promises to build task list ...

First off, the 3 ways:
Passing in a callback:
gulp.task('sync', function (cb) {  
    // setTimeout could be any async task
    setTimeout(function () {
        cb();
    }, 1000);
});
Returning a stream:
gulp.task('sync', function () {  
    return gulp.src('js/*.js')
        .pipe(concat('script.min.js')
        .pipe(uglify())
        .pipe(gulp.dest('../dist/js');
});
Returning a Promise:
gulp.task('sync', function () {  
    var deferred = Q.defer();
    // setTimeout could be any async task
    setTimeout(function () {
        deferred.resolve();
    }, 1000);
    return deferred.promise;
});

No comments:

Post a Comment