Skip to content

jacksbox/p-semaphore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)