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
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> |
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 |
A promise that resolves with the result of the executed function
Promise.<any>