IMQLock class
Class IMQLock. Implements promise-based locks.
Signature:
export declare class IMQLock
Example
~~~typescript import { IMQLock, AcquiredLock } from '.';
async function doSomething(): Promise<number | AcquiredLock
if (IMQLock.locked('doSomething')) { // avoiding err handling in this way can cause ded-locks // so it is good always try catch locked calls! // BTW, IMQLock uses timeouts to avoid dead-locks try
catch (err) { // release acquired locks with error IMQLock.release('doSomething', null, err); throw err; } }
return lock; }
(async () => { for (let i = 0; i < 10; ++i) { // run doSomething() asynchronously 10 times doSomething().then((res) => console.log(res)); } })(); ~~~
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
number |
Deadlock timeout in milliseconds {number} | |
|
|
ILogger |
Logger used to log errors which appears during locked calls {ILogger} |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
|
Acquires a lock for a given key | |
|
|
Returns true if given key is locked, false otherwise | |
|
|
Releases previously acquired lock for a given key |