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

Method traceCallback

lib/diagnostics_channel.js:592–627  ·  view source on GitHub ↗
(fn, position = -1, context = kEmptyObject, thisArg, ...args)

Source from the content-addressed store, hash-verified

590 }
591
592 traceCallback(fn, position = -1, context = kEmptyObject, thisArg, ...args) {
593 if (!this.hasSubscribers) {
594 return ReflectApply(fn, thisArg, args);
595 }
596
597 const { error } = this;
598 const continuationWindow = this.#continuationWindow;
599
600 function wrappedCallback(err, res) {
601 if (err) {
602 context.error = err;
603 error.publish(context);
604 } else {
605 context.result = res;
606 }
607
608 // Use continuation window for asyncStart/asyncEnd around callback
609 // eslint-disable-next-line no-unused-vars
610 using scope = continuationWindow.withScope(context);
611 return ReflectApply(callback, this, arguments);
612 }
613
614 const callback = ArrayPrototypeAt(args, position);
615 validateFunction(callback, 'callback');
616 ArrayPrototypeSplice(args, position, 1, wrappedCallback);
617
618 // eslint-disable-next-line no-unused-vars
619 using scope = this.#callWindow.withScope(context);
620 try {
621 return ReflectApply(fn, thisArg, args);
622 } catch (err) {
623 context.error = err;
624 error.publish(context);
625 throw err;
626 }
627 }
628}
629
630function tracingChannel(nameOrChannels) {

Calls 2

withScopeMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected