forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucks.d.ts
113 lines (91 loc) · 2.52 KB
/
bucks.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Type definitions for bucks.js 0.8.3
// Project: https://github.com/CyberAgent/bucks.js
// Definitions by: Shunsuke Ohtani <https://github.com/zaneli>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace Bucks {
interface BucksStatic {
/**
* bucks.js version.
*/
VERSION: string;
/**
* If set `true`, uncaught errors are logged.
*/
DEBUG: boolean;
/**
* Running bucks objects.
*/
running: Bucks[];
/**
* Not yet called `end` bucks object.
*/
living: Bucks[];
/**
* Create bucks object.
*/
new(): Bucks;
/**
* Catch all errors.
* @param onError Function called after catching error
*/
onError(onError: (err:Error, bucks:Bucks)=>any): void;
}
interface Bucks {
/**
* Add a task.
* @param task Function added async chain
*/
add(task: TaskWithNext): Bucks;
/**
* Add a task called only in case of success.
* @param onSuccess Function called only in case of success
*/
then(onSuccess: (res:any, next?:Task)=>any): Bucks;
/**
* Add a empty task.
*/
empty(): Bucks;
/**
* Add a task called only in case of error.
* @param onError Function called only in case of error
*/
error(onError: (err:Error, next?:Task)=>any): Bucks;
/**
* Add tasks in asynchronous way and join their results.
* @param tasks Functions called in asynchronous way and join their results
*/
parallel(tasks: TaskWithNext[]): Bucks;
/**
* Add tasks in asynchronous way and join their results.
* @param tasks Functions added async chain
*/
waterfall(tasks: TaskWithNext[]): Bucks;
/**
* Add delay execution.
* @param ms number millisecond for delaying
*/
delay(ms: number): Bucks;
/**
* Called when destroy async chain.
*/
dispose(): void;
/**
* Destroy this object and call last callback function.
* @param err If specify err and no callback, throw to execute failure callback
*/
destroy(err?: Error): Bucks;
/**
* Complete creating async chain and start executing.
* @param callback Last callback function
* @param errback Handler for occurring error in last callback function
*/
end(callback?: Task, errback?: (err:Error)=>any): void;
}
interface TaskWithNext {
(err?: Error, res?: any, next?: Task): any;
}
interface Task {
(err?: Error, res?: any): any;
}
}
declare var Bucks: Bucks.BucksStatic;