1.0.0 • Published 6 years ago

@seangenabe/semaphore v1.0.0

Weekly downloads
6
License
MIT
Repository
gitlab
Last release
6 years ago

Semaphore

Simple async semaphore

If you like this package, be sure to star its repo, and please consider donating.

Usage

import { Semaphore } from "@seangenabe/semaphore"

const semaphore = new Semaphore(64)

;(async () => {
  const release = await semaphore.wait()
  // ...
  release()
})()

const semaphore = new Semaphore(initialSize)

Parameters:

  • initialSize - the maximum number of claims allowed. Must be a positive integer or Infinity.

Creates a new semaphore with the specified size.

semaphore.wait(): Promise<() => void>

Returns: Promise<() => void>

Waits for other claims on this semaphore, then resolves with a function that can be called to release the claim on this semaphore.

semaphore.size: number

Read-only access to the remaining number of claims that can be taken.