-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks: execute unhandledRejection cb in Promise execution context
This commit now executes `process.on('unhandledRejection')` in the async execution context of the concerned `Promise`.
- Loading branch information
Sajal Khandelwal
committed
Feb 8, 2021
1 parent
907d6b6
commit 8699a07
Showing
4 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
const initHooks = require('./init-hooks'); | ||
const async_hooks = require('async_hooks'); | ||
|
||
if (!common.isMainThread) | ||
common.skip('Worker bootstrapping works differently -> different async IDs'); | ||
|
||
const promiseAsyncIds = []; | ||
const hooks = initHooks({ | ||
oninit(asyncId, type) { | ||
if (type === 'PROMISE') { | ||
promiseAsyncIds.push(asyncId); | ||
} | ||
} | ||
}); | ||
|
||
hooks.enable(); | ||
|
||
// Promise.resolve() | ||
// .then(() => { | ||
// throw new Error('Throwing on purpose'); | ||
// }); | ||
|
||
Promise.reject(); | ||
|
||
process.on('unhandledRejection', common.mustCall(() => { | ||
// assert.strictEqual(promiseAsyncIds.length, 2); | ||
// assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[1]); | ||
|
||
assert.strictEqual(promiseAsyncIds.length, 1); | ||
assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[0]); | ||
})); |