forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncblock.d.ts
73 lines (60 loc) · 2.7 KB
/
asyncblock.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Type definitions for asyncblock 2.1.23
// Project: https://github.com/scriby/asyncblock
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "asyncblock" {
function asyncblock<T>(f: (flow: asyncblock.IFlow) => void, callback?: (err: any, res: T) => void): void;
module asyncblock {
export function nostack<T>(f: (flow: asyncblock.IFlow) => void, callback?: (err: any, res: T) => void): void;
export interface IFlow {
add(responseFormat?: string[]): IExecuteFunction;
add(key: string, responseFormat?: string[]): IExecuteFunction;
add(key: number, responseFormat?: string[]): IExecuteFunction;
add(options: IFlowOptions): IExecuteFunction;
callback(responseFormat?: string[]): IExecuteFunction;
callback(key: string, responseFormat?: string[]): IExecuteFunction;
callback(key: number, responseFormat?: string[]): IExecuteFunction;
callback(options: IFlowOptions): IExecuteFunction;
wait<T>(key?: string): T;
wait<T>(key?: number): T;
get<T>(key: string): T;
set(key: string, responseFormat?: string[]): IExecuteFunction;
set(options: IFlowOptions): IExecuteFunction;
del(key: string): void;
sync<T>(task: any): T;
queue(toExecute: IExecuteFunction): void;
queue(key: string, toExecute: IExecuteFunction): void;
queue(key: number, toExecute: IExecuteFunction): void;
queue(responseFormat: string[], toExecute: IExecuteFunction): void;
queue(key: string, responseFormat: string[], toExecute: IExecuteFunction): void;
queue(key: number, responseFormat: string[], toExecute: IExecuteFunction): void;
queue(options: IFlowOptions, toExecute: IExecuteFunction): void;
doneAdding(): void;
forceWait<T>(): T;
maxParallel: number;
errorCallback: (err: any) => void;
taskTimeout: number;
timeoutIsError: boolean;
}
export interface IFlowOptions {
ignoreError?: boolean; // default false
key?: string; // string | number
responseFormat?: string[];
timeout?: number;
timeoutIsError?: boolean;
dontWait?: boolean;
firstArgIsError?: boolean; // default true
}
export interface IExecuteFunction {
<T1, T2, T3>(err: any, res1: T1, res2: T2, res3: T3): any;
<T1, T2>(err: any, res1: T1, res2: T2): any;
<T>(err: any, res: T): any;
(err: any): any;
// firstArgIsError === false
<T1, T2, T3>(res1: T1, res2: T2, res3: T3): any;
<T1, T2>(res1: T1, res2: T2): any;
<T>(res: T): any;
}
}
export = asyncblock;
}