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

Function buildCurrentResource

benchmark/async_hooks/async-resource-vs-destroy.js:25–64  ·  view source on GitHub ↗
(getServe)

Source from the content-addressed store, hash-verified

23});
24
25function buildCurrentResource(getServe) {
26 const server = createServer(getServe(getCLS, setCLS));
27 const hook = createHook({ init });
28 const cls = Symbol('cls');
29 hook.enable();
30
31 return {
32 server,
33 close,
34 };
35
36 function getCLS() {
37 const resource = executionAsyncResource();
38 if (!resource[cls]) {
39 return null;
40 }
41 return resource[cls].state;
42 }
43
44 function setCLS(state) {
45 const resource = executionAsyncResource();
46 if (!resource[cls]) {
47 resource[cls] = { state };
48 } else {
49 resource[cls].state = state;
50 }
51 }
52
53 function init(asyncId, type, triggerAsyncId, resource) {
54 const cr = executionAsyncResource();
55 if (cr !== null) {
56 resource[cls] = cr[cls];
57 }
58 }
59
60 function close() {
61 hook.disable();
62 server.close();
63 }
64}
65
66function buildDestroy(getServe) {
67 const transactions = new Map();

Callers

nothing calls this directly

Calls 4

createServerFunction · 0.50
createHookFunction · 0.50
SymbolFunction · 0.50
enableMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…