File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const {
2525
2626const {
2727 getDefaultTriggerAsyncId,
28+ getHookArrays,
2829 newAsyncId,
2930 initHooksExist,
3031 emitInit,
@@ -158,13 +159,19 @@ const defaultMicrotaskResourceOpts = { requireManualDestroy: true };
158159function queueMicrotask ( callback ) {
159160 validateFunction ( callback , 'callback' ) ;
160161
161- const asyncResource = new AsyncResource (
162- 'Microtask' ,
163- defaultMicrotaskResourceOpts ,
164- ) ;
165- asyncResource . callback = callback ;
166-
167- enqueueMicrotask ( FunctionPrototypeBind ( runMicrotask , asyncResource ) ) ;
162+ const contextFrame = AsyncContextFrame . current ( ) ;
163+ if ( contextFrame || getHookArrays ( ) [ 0 ] . length > 0 ) {
164+ // Slow path: need async hooks or context frame propagation
165+ const asyncResource = new AsyncResource (
166+ 'Microtask' ,
167+ defaultMicrotaskResourceOpts ,
168+ ) ;
169+ asyncResource . callback = callback ;
170+ enqueueMicrotask ( FunctionPrototypeBind ( runMicrotask , asyncResource ) ) ;
171+ } else {
172+ // Fast path: no hooks, no context frames - just enqueue directly
173+ enqueueMicrotask ( callback ) ;
174+ }
168175}
169176
170177module . exports = {
Original file line number Diff line number Diff line change 11Error: test
22 at one (*fixtures*async-error.js:4:9)
33 at two (*fixtures*async-error.js:17:9)
4- at process.processTicksAndRejections (node:internal*process*task_queues:103 :5)
4+ at process.processTicksAndRejections (node:internal*process*task_queues:104 :5)
55 at async three (*fixtures*async-error.js:20:3)
66 at async four (*fixtures*async-error.js:24:3)
77 at async main (*async_error_nexttick_main.js:7:5)
You can’t perform that action at this time.
0 commit comments