A simple ES6 semaphore implementation for managing concurrent access to a resource.
yarn add @dutu/semaphore@github:dutu/semaphore
import Semaphore from '@dutu/semaphore'
const sem = new Semaphore()
async function task() {
console.log("Waiting for semaphore...")
await sem.wait()
console.log("Semaphore is green. Continuing task...")
}
sem.red()
task()
setTimeout(() => {
sem.green()
}, 5000)
See the API documentation for more details on how to use it.