Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Forked from rkaw92/when-failure.js
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancavalier/0167775f761b48b5233b to your computer and use it in GitHub Desktop.
Save briancavalier/0167775f761b48b5233b to your computer and use it in GitHub Desktop.
var when1 = require('when1');
var when2 = require('when2');
when1.Promise.onPotentiallyUnhandledRejectionHandled = function(r) {
console.log('when1 Handled', r);
}
var rejectedPromise = when1.reject(new Error('Intentional failure'));
when2(rejectedPromise).done(undefined, function(error){
console.log('Rejection properly handled:', error);
});
var when1 = require('when1');
var when2 = require('when2');
var rejections = [];
var timeout;
when1.Promise.onPotentiallyUnhandledRejection = function(r) {
rejections.push(r);
if(!timeout) timeout = setTimeout(report, 100);
}
when1.Promise.onPotentiallyUnhandledRejectionHandled = function(r) {
rejections.splice(rejections.indexOf(r), 1);
}
function report() {
timeout = void 0;
rejections.forEach(function(r) {
if(!r.handled) {
console.error(r.value && r.value.stack || r.value);
}
});
rejections = [];
}
var rejectedPromise = when1.reject(new Error('Intentional failure'));
when2(rejectedPromise).done(undefined, function(error){
console.log('Rejection properly handled:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment