diff --git a/src/debuggability.js b/src/debuggability.js index 6591449ca..8a97eab68 100644 --- a/src/debuggability.js +++ b/src/debuggability.js @@ -39,7 +39,10 @@ Promise.prototype.suppressUnhandledRejections = function() { Promise.prototype._ensurePossibleRejectionHandled = function () { if ((this._bitField & IS_REJECTION_IGNORED) !== 0) return; this._setRejectionIsUnhandled(); - async.invokeLater(this._notifyUnhandledRejection, this, undefined); + var self = this; + setTimeout(function() { + self._notifyUnhandledRejection(); + }, 1); }; Promise.prototype._notifyUnhandledRejectionIsHandled = function () { diff --git a/test/mocha/unhandled_rejections.js b/test/mocha/unhandled_rejections.js index 46f19f4af..cf36add80 100644 --- a/test/mocha/unhandled_rejections.js +++ b/test/mocha/unhandled_rejections.js @@ -752,3 +752,25 @@ describe("Unhandled rejection when joining chains with common rejected parent", return Promise.all([test1, test2]); }); }); + +var asyncAwaitSupported = (function() { + try { + new Function("async function abc() {}"); + return true; + } catch (e) { + return false; + } +})(); + +if (asyncAwaitSupported) { + describe("No unhandled rejection from async await", function () { + setupCleanUps(); + specify("gh-1404", function testFunction() { + var ret = onUnhandledFail(testFunction); + Promise.using(Promise.resolve(), + (new Function("Bluebird", "return async function() { await Bluebird.reject(new Error('foo')); }"))(Promise)) + .caught(function() {}); + return ret; + }); + }); +}