Initial commit
[yaffs-website] / node_modules / currently-unhandled / core.js
1 'use strict';
2 var arrayFindIndex = require('array-find-index');
3
4 module.exports = function () {
5         var unhandledRejections = [];
6
7         function onUnhandledRejection(reason, promise) {
8                 unhandledRejections.push({reason: reason, promise: promise});
9         }
10
11         function onRejectionHandled(promise) {
12                 var index = arrayFindIndex(unhandledRejections, function (x) {
13                         return x.promise === promise;
14                 });
15
16                 unhandledRejections.splice(index, 1);
17         }
18
19         function currentlyUnhandled() {
20                 return unhandledRejections.map(function (entry) {
21                         return {
22                                 reason: entry.reason,
23                                 promise: entry.promise
24                         };
25                 });
26         }
27
28         return {
29                 onUnhandledRejection: onUnhandledRejection,
30                 onRejectionHandled: onRejectionHandled,
31                 currentlyUnhandled: currentlyUnhandled
32         };
33 };