Stream Semaphore
Node.js semaphore for streams. This module allows you to prevent race conditions across independent concurrent streams.
An example use case is preventing a race condition with using gulp-rev with the merge
option across multiple streams.
For example, if there is a JS task and a CSS task that both try to write the rev manifest with the merge option, if they happen to finish at the same time, one will overwrite the other instead of merging.
This does not happen all the time but is pain to debug and account for, especially in CI environments.
This module would lock one of the streams until it finishes writing the rev manifest and then would allow the other stream to proceed.
It can also be used as a general-purpose promise-based semaphore.
Usage
All lock/unlock functions require two parameters: semaphore name and lock name. This allows multiple independent semaphores and multiple streams per lock.
Regular semaphore usage
var sem = ; sem; sem; sem; sem;
Usage with gulp
var gulp = ;var run = ;var through2 = ;var sem = ; gulp; gulp; gulp;
Example with gulp-rev
gulp; gulp;