Skip to content

Commit

Permalink
update docs to match async-done - closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Sep 1, 2014
1 parent 75df65e commit ed2d27c
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,57 @@ async-settle

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

Handles completion and errors for callbacks, promises, observables and streams.

Will run call the function on `nextTick`. This will cause all functions to be async.

## Usage

### Successful completion

```js
var asyncSettle = require('async-settle');

asyncSettle(function(done){
// do async things
done(null, 2);
}, function(error, result){
// `error` will ALWAYS be null on execution of the first function.
// `result` will ALWAYS be a settled object with the result or error of the first function.
});
```

### Failed completion

```js
var asyncSettle = require('async-settle');

asyncSettle(function(done){
// do async things
done(new Error('Some Error Occurred'));
}, function(error, result){
// `error` will ALWAYS be null on execution of the first function.
// `result` will ALWAYS be a settled object with the result or error of the first function.
});
```

## API

### `settle(executor, onComplete)` : Function
### `asyncSettle(fn, callback)`

Takes a function to execute (`fn`) and a function to call on completion (`callback`).

#### `fn([done])`

Optionally takes a callback to call when async tasks are complete.

Takes a function to execute (`executor`) and a function to call on completion (`onComplete`).
Executed in the context of [`async-done`](https://github.com/phated/async-done), with all errors and results being settled.

`executer` is executed in the context of [`async-done`](https://github.com/phated/async-done), with all errors and results being settled.
Completion is handled by [`async-done` completion and error resolution](https://github.com/phated/async-done#completion-and-error-resolution).

`onComplete` will be called with a settled value.
#### `callback` will be called with a settled object.

#### Settled Values
#### Settled Object

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

Expand Down

0 comments on commit ed2d27c

Please # to comment.