UNPKG

1.25 kBTypeScriptView Raw
1// Type definitions for async-lock 1.1
2// Project: https://github.com/rain1017/async-lock, https://github.com/rogierschouten/async-lock
3// Definitions by: Alejandro <https://github.com/afharo>
4// Anatoly <https://github.com/rhymmor>
5// Humulus <https://github.com/humulus>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7// TypeScript Version: 2.1
8
9type AsyncLockDoneCallback<T> = (err?: Error, ret?: T) => void;
10
11interface AsyncLockOptions {
12 timeout?: number | undefined;
13 maxPending?: number | undefined;
14 maxOccupationTime?: number | undefined;
15 domainReentrant?: boolean | undefined;
16 Promise?: any;
17 skipQueue?: boolean | undefined;
18}
19
20declare class AsyncLock {
21 constructor(options?: AsyncLockOptions);
22
23 acquire<T>(key: string | string[],
24 fn: (() => T | PromiseLike<T>) | ((done: AsyncLockDoneCallback<T>) => any),
25 opts?: AsyncLockOptions): Promise<T>;
26 acquire<T>(key: string | string[],
27 fn: (done: AsyncLockDoneCallback<T>) => any,
28 cb: AsyncLockDoneCallback<T>,
29 opts?: AsyncLockOptions): void;
30
31 isBusy(key?: string): boolean;
32}
33
34declare namespace AsyncLock { }
35
36export = AsyncLock;