dutu / semaphore

A simple ES6 semaphore implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

A simple ES6 semaphore implementation


Languages

Language:JavaScript 100.0%