boundedChannel.run(context, fn[, thisArg[, ...args]])


  • context <Object> 用于关联事件的共享对象
  • fn <Function> 用于封装跟踪的函数
  • thisArg <any> 用于函数调用的接收器
  • ...args <any> 传递给函数的可选参数
  • 返回:<any> 给定函数的返回值

跟踪一个同步函数调用。这将在执行期间产生一个 start 事件和 end 事件。它使用 [channel.runStores(context, ...)][channel.runStores(context, ...)]start 通道上运行给定的函数,这确保所有事件的任何绑定存储都已设置为匹配此跟踪上下文。

🌐 Trace a synchronous function call. This will produce a start event and end event around the execution. This runs the given function using channel.runStores(context, ...) on the start channel which ensures all events have any bound stores set to match this trace context.

import { boundedChannel } from 'node:diagnostics_channel';

const wc = boundedChannel('my-operation');

const result = wc.run({ operationId: '123' }, () => {
  // Perform operation
  return 42;
});const { boundedChannel } = require('node:diagnostics_channel');

const wc = boundedChannel('my-operation');

const result = wc.run({ operationId: '123' }, () => {
  // Perform operation
  return 42;
});