/semaphore

A simple ES6 semaphore implementation

Primary LanguageJavaScript

GitHub Workflow Status

semaphore

A simple ES6 semaphore implementation for managing concurrent access to a resource.

Installation

yarn add @dutu/semaphore@github:dutu/semaphore

Usage

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.