UNPKG

697 BJavaScriptView Raw
1var Promise = require('unexpected-bluebird');
2
3var workQueue = {
4 queue: [],
5 drain: function drain() {
6 this.queue.forEach(function (fn) {
7 fn();
8 });
9 this.queue = [];
10 }
11};
12
13var scheduler = Promise.setScheduler(function (fn) {
14 workQueue.queue.push(fn);
15 scheduler(function () {
16 workQueue.drain();
17 });
18});
19
20Promise.prototype._notifyUnhandledRejection = function() {
21 var that = this;
22 scheduler(function () {
23 if (that._isRejectionUnhandled()) {
24 if (workQueue.onUnhandledRejection) {
25 // for testing
26 workQueue.onUnhandledRejection(that.reason());
27 } else {
28 throw that.reason();
29 }
30 }
31 });
32};
33
34module.exports = workQueue;