UNPKG

1.85 kBTypeScriptView Raw
1/** @module lock */
2/**
3 * Interface for locks to synchronize work or parallel processes and to prevent collisions.
4 *
5 * The lock allows to manage multiple locks identified by unique keys.
6 */
7export interface ILock {
8 /**
9 * Makes a single attempt to acquire a lock by its key.
10 * It returns immediately a positive or negative result.
11 *
12 * @param correlationId (optional) transaction id to trace execution through call chain.
13 * @param key a unique lock key to acquire.
14 * @param ttl a lock timeout (time to live) in milliseconds.
15 * @param callback callback function that receives a lock result or error.
16 */
17 tryAcquireLock(correlationId: string, key: string, ttl: number, callback: (err: any, result: boolean) => void): void;
18 /**
19 * Makes multiple attempts to acquire a lock by its key within give time interval.
20 *
21 * @param correlationId (optional) transaction id to trace execution through call chain.
22 * @param key a unique lock key to acquire.
23 * @param ttl a lock timeout (time to live) in milliseconds.
24 * @param timeout a lock acquisition timeout.
25 * @param callback callback function that receives error or null for success.
26 */
27 acquireLock(correlationId: string, key: string, ttl: number, timeout: number, callback: (err: any) => void): void;
28 /**
29 * Releases prevously acquired lock by its key.
30 *
31 * @param correlationId (optional) transaction id to trace execution through call chain.
32 * @param key a unique lock key to release.
33 * @param callback callback function that receives error or null for success.
34 */
35 releaseLock(correlationId: string, key: string, callback?: (err: any) => void): void;
36}