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

Method constructor

lib/async_hooks.js:180–217  ·  view source on GitHub ↗
(type, opts = kEmptyObject)

Source from the content-addressed store, hash-verified

178
179class AsyncResource {
180 constructor(type, opts = kEmptyObject) {
181 validateString(type, 'type');
182
183 let triggerAsyncId = opts;
184 let requireManualDestroy = false;
185 if (typeof opts !== 'number') {
186 triggerAsyncId = opts.triggerAsyncId === undefined ?
187 getDefaultTriggerAsyncId() : opts.triggerAsyncId;
188 requireManualDestroy = !!opts.requireManualDestroy;
189 }
190
191 // Unlike emitInitScript, AsyncResource doesn't supports null as the
192 // triggerAsyncId.
193 if (!NumberIsSafeInteger(triggerAsyncId) || triggerAsyncId < -1) {
194 throw new ERR_INVALID_ASYNC_ID('triggerAsyncId', triggerAsyncId);
195 }
196
197 this[contextFrameSymbol] = AsyncContextFrame.current();
198
199 const asyncId = newAsyncId();
200 this[async_id_symbol] = asyncId;
201 this[trigger_async_id_symbol] = triggerAsyncId;
202
203 if (initHooksExist()) {
204 if (type.length === 0) {
205 throw new ERR_ASYNC_TYPE(type);
206 }
207
208 emitInit(asyncId, type, triggerAsyncId, this);
209 }
210
211 if (!requireManualDestroy && destroyHooksExist()) {
212 // This prop name (destroyed) has to be synchronized with C++
213 const destroyed = { destroyed: false };
214 this[destroyedSymbol] = destroyed;
215 registerDestroyHook(this, asyncId, destroyed);
216 }
217 }
218
219 runInAsyncScope(fn, thisArg, ...args) {
220 const asyncId = this[async_id_symbol];

Callers

nothing calls this directly

Calls 5

getDefaultTriggerAsyncIdFunction · 0.85
newAsyncIdFunction · 0.85
initHooksExistFunction · 0.85
destroyHooksExistFunction · 0.85
currentMethod · 0.45

Tested by

no test coverage detected