1 |
const Promise = require('unexpected-bluebird');
|
16✔ |
2 |
|
|
3 |
const workQueue = { |
16✔ |
4 |
queue: [],
|
|
5 |
drain() { |
|
6 |
this.queue.forEach((fn) => {
|
10,182✔ |
7 |
fn(); |
4,676✔ |
8 |
}); |
|
9 |
this.queue = [];
|
10,182✔ |
10 |
}, |
|
11 |
}; |
|
12 |
|
|
13 |
const scheduler = Promise.setScheduler((fn) => { |
16✔ |
14 |
workQueue.queue.push(fn); |
4,656✔ |
15 |
scheduler(() => { |
4,656✔ |
16 |
workQueue.drain(); |
4,656✔ |
17 |
}); |
|
18 |
}); |
|
19 |
|
|
20 |
Promise.prototype._notifyUnhandledRejection = function () { |
16✔ |
21 |
const that = this;
|
1,340✔ |
22 |
scheduler(() => { |
1,340✔ |
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 |
|
|
34 |
module.exports = workQueue; |
16✔ |