Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add explanation why keep var with for loop in async_hooks #30380

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/internal/async_hooks.js
Expand Up @@ -129,6 +129,7 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) {
active_hooks.call_depth += 1;
// Use a single try/catch for all hooks to avoid setting up one per iteration.
try {
// Using var here instead of let because "for (var ...)" is faster than let
gireeshpunathil marked this conversation as resolved.
Show resolved Hide resolved
for (var i = 0; i < active_hooks.array.length; i++) {
if (typeof active_hooks.array[i][init_symbol] === 'function') {
active_hooks.array[i][init_symbol](
Expand Down Expand Up @@ -159,6 +160,7 @@ function emitHook(symbol, asyncId) {
// Use a single try/catch for all hook to avoid setting up one per
// iteration.
try {
// Using var here instead of let because "for (var ...)" is faster than let
gireeshpunathil marked this conversation as resolved.
Show resolved Hide resolved
for (var i = 0; i < active_hooks.array.length; i++) {
if (typeof active_hooks.array[i][symbol] === 'function') {
active_hooks.array[i][symbol](asyncId);
Expand Down