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

Function buildAsyncLocalStorage

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

Source from the content-addressed store, hash-verified

99}
100
101function buildAsyncLocalStorage(getServe) {
102 const asyncLocalStorage = new AsyncLocalStorage();
103 const server = createServer((req, res) => {
104 asyncLocalStorage.run({}, () => {
105 getServe(getCLS, setCLS)(req, res);
106 });
107 });
108
109 return {
110 server,
111 close,
112 };
113
114 function getCLS() {
115 const store = asyncLocalStorage.getStore();
116 if (store === undefined) {
117 return null;
118 }
119 return store.state;
120 }
121
122 function setCLS(state) {
123 const store = asyncLocalStorage.getStore();
124 if (store === undefined) {
125 return;
126 }
127 store.state = state;
128 }
129
130 function close() {
131 asyncLocalStorage.disable();
132 server.close();
133 }
134}
135
136function getServeAwait(getCLS, setCLS) {
137 return async function serve(req, res) {

Callers

nothing calls this directly

Calls 2

runMethod · 0.95
createServerFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…