Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/channel/mod.ts>Semaphore

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
namespace Semaphore
Re-export
import { Semaphore } from "https://deno.land/x/rimbu@1.2.0/channel/mod.ts";

Interfaces

Defines the static Semaphore API.

Type Aliases

The semaphore error type.

interface Semaphore
implements Mutex
Re-export
import { type Semaphore } from "https://deno.land/x/rimbu@1.2.0/channel/mod.ts";

A Semaphore is a generalized version of a Mutex, allowing boundaries on the amount of concurrent processes that can have simultaneous access to a shared resource. The semaphore is weighted, meaning that the semaphore has a maximum size/capacity available for the shared resources. When acquiring the resource, a weight can be provided allowing more intensive tasks to acquire a larger share of the shared resource, preventing too many other tasks from also acquiring the resource.

Properties

readonly
maxSize: number

The maximum simultaneous "weight" that the semaphore allows access to for the shared resource.

Methods

canAcquire(weight?: number): boolean

Returns true if the semaphore will directly give access to the shared resource for the given weight when requested.

acquire(weight?: number): Promise<void>

Request access to a shared resource with the given weight. Blocks if the semaphore has insufficient capacity until enough weight has been released. Resolves when the semaphore has enough capacity for the operation.

release(weight?: number): void

Release obtained capacity from the semaphore to allow potential other blocked processes to access the resource.

variable Semaphore
Re-export
import { Semaphore } from "https://deno.land/x/rimbu@1.2.0/channel/mod.ts";