Gulp Task Asynchrony
You should understand that all Gulp tasks are asynchronous. What does this mean? Let's look at an example. Suppose two private tasks are called inside a public task:
function taskD(cb) {
task1(cb);
task2(cb);
cb();
}
Asynchrony means that the task2
task
will not wait for the task1
task
to complete, but will be executed
in parallel with it.
Let's think about this with a more practical example. Suppose the first task converts LESS to CSS, and the second task minifies the resulting CSS.
In this case, we will face a problem: you cannot minify a CSS file before the LESS compilation result is written to it!
However, if the tasks were executed synchronously - sequentially one after another, we would face a different problem: tasks that could be executed in parallel would be executed one after the other, slowing down Gulp's work. Let's also think about this with an example.
Suppose the first task minifies CSS files, and the second task minifies JavaScript files. Obviously, these two unrelated operations can be performed simultaneously.
Fortunately, Gulp provides tools that allow you to explicitly specify which tasks should be executed in parallel and which ones - sequentially. We will examine these tools in the next lesson.
Come up with an example of two tasks that must be executed only sequentially.
Come up with an example of two tasks that must be executed only in parallel.