Skip to content

Commit

Permalink
Merge pull request #1215 from benjamingr/patch-2
Browse files Browse the repository at this point in the history
Add Timeout & Cancellation Example to `features.md`
  • Loading branch information
benjamingr committed Aug 29, 2016
2 parents 5a381ab + f00a8d4 commit 60affdf
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,27 @@ window.onpromisechained = function(promise, child) {

##Cancellation and timeouts

See [`Cancellation`](.) for how to use cancellation.

```js
// Enable cancellation
Promise.config({cancellation: true});

var fs = Promise.promisifyAll(require("fs"));

// In 2000ms or less, load & parse a file 'config.json'
var p = Promise.resolve('./config.json')
.timeout(2000)
.catch(console.error.bind(console, 'Failed to load config!'))
.then(fs.readFileAsync)
.then(JSON.parse);
// Listen for exception event to trigger promise cancellation
process.on('unhandledException', function(event) {
// cancel config loading
p.cancel();
});
```

##Scoped prototypes

Building a library that depends on bluebird? You should know about the "scoped prototype" feature.
Expand Down

0 comments on commit 60affdf

Please sign in to comment.