How does gulp resolve dependencies before running?

It is assumed that there are four tasks: "a", "b", "c", "d" (b depends on c and d; both c and d depend on a), so the tasks are performed in the following order: / p>

a-> (c, d) β†’ b

Here's gulpfile.js, which works accordingly:

gulp.task('a'); gulp.task('c', ['a']); gulp.task('d', ['a']); gulp.task('b', ['c', 'd']); 

Despite the fact that tasks "c" and "d" depend on task "a", gulp is smart enough for task "a" to be executed only once. I am wondering when tasks are executed with maximum concurrency, how does gulp resolve dependencies before starting?

+6
source share
2 answers

Perhaps the best way to document this is: "gulp (orchestrator) works with the highest possible concurrency after taking into account all the specified dependencies."

So, in your scenario, c and d actually execute "in parallel"? Well, yes and no. Since JavaScript is single-threaded, technically the processor executes either c or d, but not both. Gulp (orchestrator) will start it, wait for it to finish, then run both c and d, and wait for both to finish, then run b.

If tasks c and d are generally asynchronous, you will see that both are running at the same time. (Note that Gulp's temporary outputs are intertwined.) If tasks are completely synchronized, technically they won’t run in parallel ... just because JavaScript is single-threaded.

The maximum possible concurrency, taking into account all the restrictions you specify.

+7
source

gulp tasks do not always work with maximum concurrency if tasks have dependencies. gulp documentation says:

Note By default, tasks run with a maximum concurrency value - for example. This launches all tasks at once and does not expect anything. If you want to create a series in which tasks are performed in a specific order, you need to do two things:

  • tell me when this will be done,
  • and let him know that the task depends on the completion of the other.

gulp uses orchestrator to run tasks, and the sequencify orchestra uses to arrange tasks in sequence.

For example, the tasks in your example will be ordered to a -> c -> d -> b or a -> d -> c -> b by sequencing and executing in sequence using an orchestra.

If I understand correctly, c and d can be executed in parallel in theory, but not with the current gulp implementation.

EDIT

It seems that

orchestrator runs c and d in parallel. It sequentially performs tasks and runs tasks that are not being performed or are being performed, and all dependencies are being executed. He reiterates that when each task is completed until all tasks are completed. See Orchestrator.prototype._runStep details.

+2
source

All Articles