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