-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 9, 2021
1 parent
beee538
commit 91fd525
Showing
5 changed files
with
130 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,27 @@ | ||
'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.reject(); | ||
|
||
process.on('unhandledRejection', common.mustCall(() => { | ||
assert.strictEqual(promiseAsyncIds.length, 1); | ||
assert.strictEqual(async_hooks.executionAsyncId(), promiseAsyncIds[0]); | ||
})); |
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