Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.