mirror of https://github.com/nodejs/node.git
node: mark promises as handled as soon as possible
Fixes: https://github.com/nodejs/io.js/issues/1912 PR-URL: https://github.com/nodejs/io.js/pull/1952 Reviewed-By: Domenic Denicola <d@domenic.me> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>pull/1952/head
parent
03ce84dfa1
commit
a251657058
12
src/node.js
12
src/node.js
|
@ -515,8 +515,12 @@
|
|||
var hasBeenNotified = hasBeenNotifiedProperty.get(promise);
|
||||
if (hasBeenNotified !== undefined) {
|
||||
hasBeenNotifiedProperty.delete(promise);
|
||||
if (hasBeenNotified === true)
|
||||
process.emit('rejectionHandled', promise);
|
||||
if (hasBeenNotified === true) {
|
||||
process.nextTick(function() {
|
||||
process.emit('rejectionHandled', promise);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -524,9 +528,7 @@
|
|||
if (event === promiseRejectEvent.unhandled)
|
||||
unhandledRejection(promise, reason);
|
||||
else if (event === promiseRejectEvent.handled)
|
||||
process.nextTick(function() {
|
||||
rejectionHandled(promise);
|
||||
});
|
||||
rejectionHandled(promise);
|
||||
else
|
||||
NativeModule.require('assert').fail('unexpected PromiseRejectEvent');
|
||||
});
|
||||
|
|
|
@ -275,6 +275,21 @@ asyncTest('Attaching a promise catch in a process.nextTick is soon enough to' +
|
|||
});
|
||||
});
|
||||
|
||||
asyncTest('While inside setImmediate, catching a rejected promise derived ' +
|
||||
'from returning a rejected promise in a fulfillment handler ' +
|
||||
'prevents unhandledRejection', function(done) {
|
||||
onUnhandledFail(done);
|
||||
|
||||
setImmediate(function() {
|
||||
// reproduces on first tick and inside of setImmediate
|
||||
Promise
|
||||
.resolve('resolve')
|
||||
.then(function() {
|
||||
return Promise.reject('reject');
|
||||
}).catch(function(e) {});
|
||||
});
|
||||
});
|
||||
|
||||
// State adapation tests
|
||||
asyncTest('catching a promise which is asynchronously rejected (via' +
|
||||
'resolution to an asynchronously-rejected promise) prevents' +
|
||||
|
|
Loading…
Reference in New Issue