1 | /** @module lock */
|
2 | import { Lock } from './Lock';
|
3 | /**
|
4 | * Lock that is used to synchronize execution within one process using shared memory.
|
5 | *
|
6 | * Remember: This implementation is not suitable for synchronization of distributed processes.
|
7 | *
|
8 | * ### Configuration parameters ###
|
9 | *
|
10 | * - __options:__
|
11 | * - retry_timeout: timeout in milliseconds to retry lock acquisition. (Default: 100)
|
12 | *
|
13 | * @see [[ILock]]
|
14 | * @see [[Lock]]
|
15 | *
|
16 | * ### Example ###
|
17 | *
|
18 | * let lock = new MemoryLock();
|
19 | *
|
20 | * lock.acquire("123", "key1", (err) => {
|
21 | * if (err == null) {
|
22 | * try {
|
23 | * // Processing...
|
24 | * } finally {
|
25 | * lock.releaseLock("123", "key1", (err) => {
|
26 | * // Continue...
|
27 | * });
|
28 | * }
|
29 | * }
|
30 | * });
|
31 | */
|
32 | export declare class MemoryLock extends Lock {
|
33 | private _locks;
|
34 | /**
|
35 | * Makes a single attempt to acquire a lock by its key.
|
36 | * It returns immediately a positive or negative result.
|
37 | *
|
38 | * @param correlationId (optional) transaction id to trace execution through call chain.
|
39 | * @param key a unique lock key to acquire.
|
40 | * @param ttl a lock timeout (time to live) in milliseconds.
|
41 | * @param callback callback function that receives a lock result or error.
|
42 | */
|
43 | tryAcquireLock(correlationId: string, key: string, ttl: number, callback: (err: any, result: boolean) => void): void;
|
44 | /**
|
45 | * Releases the lock with the given key.
|
46 | *
|
47 | * @param correlationId not used.
|
48 | * @param key the key of the lock that is to be released.
|
49 | * @param callback (optional) the function to call once the lock has been released. Will be called
|
50 | * with <code>null</code>.
|
51 | */
|
52 | releaseLock(correlationId: string, key: string, callback?: (err: any) => void): void;
|
53 | }
|