GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — async_hooks: use hasHooks function internally · nodejs/node@2c5b014

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • async_hooks.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/internal/async_hooks.js
+13-9Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,27 +299,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) {
299299
}
300300
}
301301

302+
function hasHooks(key) {
303+
return async_hook_fields[key] > 0;
304+
}
305+
302306
function enabledHooksExist() {
303-
return async_hook_fields[kCheck] > 0;
307+
return hasHooks(kCheck);
304308
}
305309

306310
function initHooksExist() {
307-
return async_hook_fields[kInit] > 0;
311+
return hasHooks(kInit);
308312
}
309313

310314
function afterHooksExist() {
311-
return async_hook_fields[kAfter] > 0;
315+
return hasHooks(kAfter);
312316
}
313317

314318
function destroyHooksExist() {
315-
return async_hook_fields[kDestroy] > 0;
319+
return hasHooks(kDestroy);
316320
}
317321

318322

319323
function emitInitScript(asyncId, type, triggerAsyncId, resource) {
320324
// Short circuit all checks for the common case. Which is that no hooks have
321325
// been set. Do this to remove performance impact for embedders (and core).
322-
if (async_hook_fields[kInit] === 0)
326+
if (!hasHooks(kInit))
323327
return;
324328

325329
if (triggerAsyncId === null) {
@@ -333,13 +337,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) {
333337
function emitBeforeScript(asyncId, triggerAsyncId) {
334338
pushAsyncIds(asyncId, triggerAsyncId);
335339

336-
if (async_hook_fields[kBefore] > 0)
340+
if (hasHooks(kBefore))
337341
emitBeforeNative(asyncId);
338342
}
339343

340344

341345
function emitAfterScript(asyncId) {
342-
if (async_hook_fields[kAfter] > 0)
346+
if (hasHooks(kAfter))
343347
emitAfterNative(asyncId);
344348

345349
popAsyncIds(asyncId);
@@ -348,7 +352,7 @@ function emitAfterScript(asyncId) {
348352

349353
function emitDestroyScript(asyncId) {
350354
// Return early if there are no destroy callbacks, or invalid asyncId.
351-
if (async_hook_fields[kDestroy] === 0 || asyncId <= 0)
355+
if (!hasHooks(kDestroy) || asyncId <= 0)
352356
return;
353357
async_wrap.queueDestroyAsyncId(asyncId);
354358
}
@@ -364,7 +368,7 @@ function clearAsyncIdStack() {
364368

365369

366370
function hasAsyncIdStack() {
367-
return async_hook_fields[kStackLength] > 0;
371+
return hasHooks(kStackLength);
368372
}
369373

370374

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.