-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks: set unhandledRejection async context
This commit now executes `process.on('unhandledRejection')` in the async execution context of the concerned `Promise`. PR-URL: #37281 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
1 parent
1fc8307
commit d0f1ff5
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