1
0
mirror of https://github.com/thangisme/notes.git synced 2024-10-31 23:37:18 -04:00
notes/node_modules/currently-unhandled/core.js
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00

34 lines
747 B
JavaScript

'use strict';
var arrayFindIndex = require('array-find-index');
module.exports = function () {
var unhandledRejections = [];
function onUnhandledRejection(reason, promise) {
unhandledRejections.push({reason: reason, promise: promise});
}
function onRejectionHandled(promise) {
var index = arrayFindIndex(unhandledRejections, function (x) {
return x.promise === promise;
});
unhandledRejections.splice(index, 1);
}
function currentlyUnhandled() {
return unhandledRejections.map(function (entry) {
return {
reason: entry.reason,
promise: entry.promise
};
});
}
return {
onUnhandledRejection: onUnhandledRejection,
onRejectionHandled: onRejectionHandled,
currentlyUnhandled: currentlyUnhandled
};
};