← Back

TIL: async gulp tasks

Thinking about starting a new series of posts that are just quick tech related things I'm learning.

Today's is about gulp.

In our gulp file we were doing something like this:

gulp.task("one", function(){  
    // creates a file
});
gulp.task("two", function(){  
    var file = require("./file.js");
    //do something with that file
});
gulp.task("build", ["one","two"]);  

This would work---ish. It would build it properly, and read it properly. But because of the way gulp kicks off each of it's tasks, it would throw an error in the console, even if it could gracefully recover from that error. But today I learned via the power of stack overflow link a coworker sent me that you can give a gulp task a prerequisite task. So that it won't kick off the second task before it completes the first.

gulp.task("one", function(){  
    // creates a file
});
gulp.task("two", ["one"], function(){  
    var file = require("./file.js");
    //do something with that file
});
gulp.task("build", ["one","two"]);  

Neat right?


← Back home