-
-
Save briancavalier/0167775f761b48b5233b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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