Skip to content

Commit

Permalink
doc: clean up promise rejection tracking sample
Browse files Browse the repository at this point in the history
By using a Set instead of array we can get O(1) deletion. Also fixed
indentation to align with the rest of the document.
  • Loading branch information
domenic committed Feb 26, 2015
1 parent ce22ab0 commit 5377f2e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions doc/api/process.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,12 @@ event tells you when the list of unhandled rejections shrinks.
For example using the rejection detection hooks in order to keep a list of all
the rejected promises at a given time:

var unhandledRejections = [];
var unhandledRejections = new Set();
process.on('unhandledRejection', function(reason, p) {
unhandledRejections.push(p);
unhandledRejections.add(p);
});
process.on('rejectionHandled', function(p) {
var index = unhandledRejections.indexOf(p);
unhandledRejections.splice(index, 1);
unhandledRejections.delete(p);
});

You could then record this list in some error log, either periodically or upon
Expand Down

0 comments on commit 5377f2e

Please sign in to comment.