Skip to content

Commit

Permalink
Clarify opening example. Fixes kriskowal#332.
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Jul 4, 2013
1 parent 6eedcd9 commit 2eb6613
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ step1(function (value1) {
With a promise library, you can flatten the pyramid.

```javascript
Q.fcall(step1)
.then(step2)
.then(step3)
.then(step4)
Q.fcall(promisedStep1)
.then(promisedStep2)
.then(promisedStep3)
.then(promisedStep4)
.then(function (value4) {
// Do something with value4
}, function (error) {
// Handle any error from step1 through step4
})
.catch(function (error) {
// Handle any error from all above steps
})
.done();
```

With this approach, you also get implicit error propagation,
just like ``try``, ``catch``, and ``finally``. An error in
``step1`` will flow all the way to ``step5``, where it’s
caught and handled.
With this approach, you also get implicit error propagation, just like `try`,
`catch`, and `finally`. An error in `promisedStep1` will flow all the way to
the `catch` function, where it’s caught and handled. (Here `promisedStepN` is
a version of `stepN` that returns a promise.)

The callback approach is called an “inversion of control”.
A function that accepts a callback instead of a return value
Expand Down

0 comments on commit 2eb6613

Please sign in to comment.