-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
48 lines (42 loc) · 1.25 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Redis, Cluster } from 'ioredis';
/**
* Release the lock only if it has the same lockValue as acquireLock sets it.
* This will not release an already released token.
*/
type ReleaseFunction = () => Promise<void>;
interface acquireOptions {
/**
* Time interval at which attempt to acquire the lock.
*
* @default 100
*/
retryTimeMillis?: number;
/**
* Time span after which the acquired lock times out and is released.
*/
timeoutMillis?: number;
/**
* Time span after which will not attempt to acquire the lock, and the `lock` function will fail.
*/
failAfterMillis?: number;
/**
* Whether or not to apply queueing fifo to the blocked instances
* if this is true, then the first one to wait will be the first one to be released and so on.
*/
fifo?: boolean;
}
/**
* Acquire mutex lock on the given resource name.
* If the lock is already acquired, wait until it's free and acquire it.
*
* @param client ioredis instance.
* @param lockName the name of the lock to be acquired.
* @param options lock acquire options.
*
* @returns a promise that resolves with release function.
*/
export function lock(
client: Redis | Cluster,
lockName: string,
options: acquireOptions
): Promise<ReleaseFunction>;