Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 550 Bytes

README.md

File metadata and controls

26 lines (18 loc) · 550 Bytes

p-semaphore

A simple async/await semaphore implementation

installation

npm install p-semaphore

usage

const semaphore = require('./p-semaphore.js')

const { V, P } = semaphore(1) // initial value (defaults to 1)
await P() // will down/wait/decrement, always has to be awaited
V()       // will up/signal/increase, syncronuse call

For convenience semaphore() also returns signal/wait as well as increment/decrement:

const { signal, wait } = semaphore(1)
const { increment, decrement } = semaphore(1)