Control concurrency of gulp tasks.
Gulp always attempts to run tasks with "maximum concurrency".
While this is usually a good thing, there are occasions where contention
over constrained resources (disk, network, memory, etc) can cause problems.
You could use something like
gulp-sequence to limit concurrency,
but that requires you to build a specific sequence for every scenario
and essentially fights against gulps task orchestrator.
gulp-lock helps you limit concurrency only where needed.
Consider the following diagram:
Properly orchestrating these tasks presents a few difficulties; Which task will be ready to run first? What if it varies (network congestion, etc)? How do you compose them as dependencies to other tasks in a non-verbose way?
gulp-lock allows you to simply identify contentious tasks, wrap them with a lock,
and then compose them with other tasks as you normally would.
var lock = ;var diskLock = ; // create a lock with a concurrency limit of 2var networkLock = ; // create a lock with default concurrency limit (1).gulp
A lock object provides three different wrapper methods for your task.
lock.cb(taskFunc)wraps a task method that takes a completion callback. Once the concurrency limit is reached, tasks will queue until a task releases it's hold on the lock by calling the callback.
lock.stream(taskFunc)wraps a task method that returns a stream. (i.e.
return gulp.src(...)). A task releases its hold on a lock when the returned stream ends.
lock.promise(taskFunc)wraps a task that returns a promise. Tasks release their hold on the lock when the promise is resolved.
Tasks are queued for execution for by gulps orchestrator. Whichever task has it's dependencies met first will be queued first. This is an attempt to maximize concurrency (within the limits set by the lock).
The "unlimited" lock provides a convenient way to disable the effects of
gulp-lock. It provides an identical api to the normal locks, but all wrapper
functions are actually identity functions that just return the function without
wrapping it. A potential usage would be to only enforce concurrency restrictions
on Travis. Travis vms often suffer from slower network/disk access than developer
machines, and you are probably willing to trade reduced concurrency (i.e. speed)
for added dependability on your travis build.
var lock = ;// only restrict concurrency on travisvar myLock = processenvTRAVIS ? : lockunlimited;// lock will have no affect outside of travisgulp
not really a gulp plugin
While this is listed as a gulp plugin, it actually has no dependency on gulp or any vinyl libraries. It can be used to control concurrency for any async functions that either:
- take a callback as their first arg.
- return a promise.
- return a stream.