()
| 36 | nativeProviders.delete('PROMISE'); |
| 37 | |
| 38 | function 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 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…