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);
|
var hasBeenNotified = hasBeenNotifiedProperty.get(promise);
|
||||||
if (hasBeenNotified !== undefined) {
|
if (hasBeenNotified !== undefined) {
|
||||||
hasBeenNotifiedProperty.delete(promise);
|
hasBeenNotifiedProperty.delete(promise);
|
||||||
if (hasBeenNotified === true)
|
if (hasBeenNotified === true) {
|
||||||
process.emit('rejectionHandled', promise);
|
process.nextTick(function() {
|
||||||
|
process.emit('rejectionHandled', promise);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,9 +528,7 @@
|
||||||
if (event === promiseRejectEvent.unhandled)
|
if (event === promiseRejectEvent.unhandled)
|
||||||
unhandledRejection(promise, reason);
|
unhandledRejection(promise, reason);
|
||||||
else if (event === promiseRejectEvent.handled)
|
else if (event === promiseRejectEvent.handled)
|
||||||
process.nextTick(function() {
|
rejectionHandled(promise);
|
||||||
rejectionHandled(promise);
|
|
||||||
});
|
|
||||||
else
|
else
|
||||||
NativeModule.require('assert').fail('unexpected PromiseRejectEvent');
|
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
|
// State adapation tests
|
||||||
asyncTest('catching a promise which is asynchronously rejected (via' +
|
asyncTest('catching a promise which is asynchronously rejected (via' +
|
||||||
'resolution to an asynchronously-rejected promise) prevents' +
|
'resolution to an asynchronously-rejected promise) prevents' +
|
||||||
|
|
Loading…
Reference in New Issue