MCPcopy Index your code
hub / github.com/nodejs/node / createHook

Function createHook

lib/internal/trace_events_async_hooks.js:38–97  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36nativeProviders.delete('PROMISE');
37
38function createHook() {
39 // In traceEvents it is not only the id but also the name that needs to be
40 // repeated. Since async_hooks doesn't expose the provider type in the
41 // non-init events, use a map to manually map the asyncId to the type name.
42
43 const hook = async_hooks.createHook({
44 init(asyncId, type, triggerAsyncId, resource) {
45 if (nativeProviders.has(type)) return;
46
47 typeMemory.set(asyncId, type);
48 trace(kBeforeEvent, kTraceEventCategory,
49 type, asyncId,
50 {
51 triggerAsyncId,
52 executionAsyncId: async_hooks.executionAsyncId(),
53 });
54 },
55
56 before(asyncId) {
57 const type = typeMemory.get(asyncId);
58 if (type === undefined) return;
59
60 trace(kBeforeEvent, kTraceEventCategory, `${type}_CALLBACK`, asyncId);
61 },
62
63 after(asyncId) {
64 const type = typeMemory.get(asyncId);
65 if (type === undefined) return;
66
67 trace(kEndEvent, kTraceEventCategory, `${type}_CALLBACK`, asyncId);
68 },
69
70 destroy(asyncId) {
71 const type = typeMemory.get(asyncId);
72 if (type === undefined) return;
73
74 trace(kEndEvent, kTraceEventCategory, type, asyncId);
75
76 // Cleanup asyncId to type map
77 typeMemory.delete(asyncId);
78 },
79 });
80
81 return {
82 enable() {
83 if (this[kEnabled])
84 return;
85 this[kEnabled] = true;
86 hook.enable();
87 },
88
89 disable() {
90 if (!this[kEnabled])
91 return;
92 this[kEnabled] = false;
93 hook.disable();
94 typeMemory.clear();
95 },

Callers

nothing calls this directly

Calls 1

createHookMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…