Skip to content

Commit 6c5fccf

Browse files
committed
Docs: Improve & match async-done docs (closes #5)
1 parent b686e96 commit 6c5fccf

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

README.md

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,61 @@ async-settle
55

66
Settle your async functions - when you need to know all your parallel functions are complete (success or failure)
77

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+
842
## API
943

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).
1155

12-
Takes a function to execute (`executor`) and a function to call on completion (`onComplete`).
56+
#### `callback(error, result)`
1357

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.
1559

16-
`onComplete` will be called with a settled value.
60+
Teh `error` argument will always be `null`.
1761

18-
#### Settled Values
62+
#### Settled Object
1963

2064
Settled values have two properties, `state` and `value`.
2165

0 commit comments

Comments
 (0)