Skip to main content

interface Mutex

A Mutex is used to restrict access to a shared resource in a concurrent environment. The Mutex can be used to acquire a lock for the resource, preventing others using the Mutex from accessing the resource. When finished using the resource, the lock can be released, allowing other waiting processes to acquire a lock.

Companion namespace: Mutex

Extends: Semaphore

Properties​

maxSize​

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

Definition​

readonly maxSize: number;

Overrides​

Semaphore.maxSize

Methods​

acquire​

Acquire a lock. Blocks if the resource is already locked. Resolves when the resource is available.

Definition​

acquire(unused?: undefined, options?: {
    signal?: AbortSignal | undefined;
    timeoutMs?: number | undefined;
  }): Promise<void>;

Parameters​

NameTypeDescription
unusedundefined
options{
    signal?: AbortSignal | undefined;
    timeoutMs?: number | undefined;
  }

Overrides​

Semaphore.acquire

canAcquire​

Returns true if the resource can be acquired immediately, false otherwise.

Definition​

canAcquire(): boolean;

Overrides​

Semaphore.canAcquire

release​

Release a lock after it is acquired. Allows other functions to obtain a lock.

Definition​

release(): void;

Overrides​

Semaphore.release