mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
async_hooks: move PromiseHook handler to JS
This avoids the need to wrap every promise in an AsyncWrap and also makes it easier to skip the machinery to track destroy events when there's no destroy listener. Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com> PR-URL: https://github.com/nodejs/node/pull/32891 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
1 parent
023bcdeb28
commit
13c5a1629c
10 files changed
+307
-66
No files matched your search
@@ -2,10 +2,31 @@
|
||||
const common = require('../common.js');
|
||||
const { createHook } = require('async_hooks');
|
||||
|
||||
let hook;
|
||||
const tests = {
|
||||
disabled() {
|
||||
hook = createHook({
|
||||
promiseResolve() {}
|
||||
});
|
||||
},
|
||||
enabled() {
|
||||
hook = createHook({
|
||||
promiseResolve() {}
|
||||
}).enable();
|
||||
},
|
||||
enabledWithDestroy() {
|
||||
hook = createHook({
|
||||
promiseResolve() {},
|
||||
destroy() {}
|
||||
}).enable();
|
||||
}
|
||||
};
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1e6],
|
||||
asyncHooks: [
|
||||
'enabled',
|
||||
'enabledWithDestroy',
|
||||
'disabled',
|
||||
]
|
||||
});
|
||||
@@ -19,10 +40,8 @@ async function run(n) {
|
||||
}
|
||||
|
||||
function main({ n, asyncHooks }) {
|
||||
const hook = createHook({ promiseResolve() {} });
|
||||
if (asyncHooks !== 'disabled') {
|
||||
hook.enable();
|
||||
}
|
||||
if (hook) hook.disable();
|
||||
tests[asyncHooks]();
|
||||
bench.start();
|
||||
run(n).then(() => {
|
||||
bench.end(n);
|
||||
|
||||
Reference in new issue
Block a user