@@ -5,17 +5,61 @@ async-settle
5
5
6
6
Settle your async functions - when you need to know all your parallel functions are complete (success or failure)
7
7
8
+ Handles completion and errors for callbacks, promises, observables and streams.
9
+
10
+ Will run call the function on ` nextTick ` . This will cause all functions to be async.
11
+
12
+ ## Usage
13
+
14
+ ### Successful completion
15
+
16
+ ``` js
17
+ var asyncSettle = require (' async-settle' );
18
+
19
+ asyncSettle (function (done ){
20
+ // do async things
21
+ done (null , 2 );
22
+ }, function (error , result ){
23
+ // `error` will ALWAYS be null on execution of the first function.
24
+ // `result` will ALWAYS be a settled object with the result or error of the first function.
25
+ });
26
+ ```
27
+
28
+ ### Failed completion
29
+
30
+ ``` js
31
+ var asyncSettle = require (' async-settle' );
32
+
33
+ asyncSettle (function (done ){
34
+ // do async things
35
+ done (new Error (' Some Error Occurred' ));
36
+ }, function (error , result ){
37
+ // `error` will ALWAYS be null on execution of the first function.
38
+ // `result` will ALWAYS be a settled object with the result or error of the first function.
39
+ });
40
+ ```
41
+
8
42
## API
9
43
10
- ### ` settle(executor, onComplete) ` : Function
44
+ ### ` asyncSettle(fn, callback) `
45
+
46
+ Takes a function to execute (` fn ` ) and a function to call on completion (` callback ` ).
47
+
48
+ #### ` fn([done]) `
49
+
50
+ Optionally takes a callback to call when async tasks are complete.
51
+
52
+ Executed in the context of [ ` async-done ` ] ( https://github.com/phated/async-done ) , with all errors and results being settled.
53
+
54
+ Completion is handled by [ ` async-done ` completion and error resolution] ( https://github.com/phated/async-done#completion-and-error-resolution ) .
11
55
12
- Takes a function to execute ( ` executor ` ) and a function to call on completion ( ` onComplete ` ).
56
+ #### ` callback(error, result) `
13
57
14
- ` executer ` is executed in the context of [ ` async-done ` ] ( https://github.com/phated/async-done ) , with all errors and results being settled .
58
+ Called on completion of ` fn ` and recieves a settled object as the ` result ` argument .
15
59
16
- ` onComplete ` will be called with a settled value .
60
+ Teh ` error ` argument will always be ` null ` .
17
61
18
- #### Settled Values
62
+ #### Settled Object
19
63
20
64
Settled values have two properties, ` state ` and ` value ` .
21
65
0 commit comments