| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9f7cc77 commit fa927c3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ const { | |||
| 25 | 25 | ||
| 26 | 26 | const { | |
| 27 | 27 | getDefaultTriggerAsyncId, | |
| 28 | + getHookArrays, | ||
| 28 | 29 | newAsyncId, | |
| 29 | 30 | initHooksExist, | |
| 30 | 31 | emitInit, | |
@@ -158,13 +159,18 @@ const defaultMicrotaskResourceOpts = { requireManualDestroy: true }; | |||
| 158 | 159 | function queueMicrotask(callback) { | |
| 159 | 160 | validateFunction(callback, 'callback'); | |
| 160 | 161 | ||
| 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 | + const asyncResource = new AsyncResource( | ||
| 165 | + 'Microtask', | ||
| 166 | + defaultMicrotaskResourceOpts, | ||
| 167 | + ); | ||
| 168 | + asyncResource.callback = callback; | ||
| 169 | + enqueueMicrotask(FunctionPrototypeBind(runMicrotask, asyncResource)); | ||
| 170 | + } else { | ||
| 171 | + // Fast path: no AsyncLocalStorage in use | ||
| 172 | + enqueueMicrotask(callback); | ||
| 173 | + } | ||
| 168 | 174 | } | |
| 169 | 175 | ||
| 170 | 176 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | Error: test | |
| 2 | 2 | at one (*fixtures*async-error.js:4:9) | |
| 3 | 3 | 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) | ||
| 5 | 5 | at async three (*fixtures*async-error.js:20:3) | |
| 6 | 6 | at async four (*fixtures*async-error.js:24:3) | |
| 7 | 7 | at async main (*async_error_nexttick_main.js:7:5) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments