1.0.0 • Published 5 years ago

p-semaphore v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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)