Class

Lock

Lock()

Constructor

# new Lock()

Provides a basic lock mechanism for controlling access to shared resources, with support for queuing and executing functions when the lock is available

Base lock implementation for concurrency control

View Source locks/Lock.ts, line 2

Example
// Using the Lock class to execute a function with exclusive access
const lock = new Lock();
const result = await lock.execute(async () => {
  // This code will run with exclusive access
  return await performCriticalOperation();
});

Methods

# async acquire(issueropt) → {Promise.<void>}

waits to acquire the lock

Parameters:
Name Type Attributes Description
issuer string <optional>

View Source locks/Lock.ts, line 88

Promise.<void>

# async execute(func) → {Promise.<any>}

Acquires the lock, executes the provided function, and releases the lock afterward, ensuring proper cleanup even if the function throws an error

Executes a function with exclusive lock access

Parameters:
Name Type Description
func function

The function to execute when the lock is acquired

View Source locks/Lock.ts, line 80

A promise that resolves with the result of the executed function

Promise.<any>

# release()

releases the lock

View Source locks/Lock.ts, line 93