Skip to content

Commit

Permalink
Add Example Timeout & Cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
justsml committed May 25, 2016
1 parent 8fac946 commit fe541fb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,29 @@ 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(function(data) {
return JSON.parse(data);
});
// 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 fe541fb

Please sign in to comment.