diagnostics_channel.boundedChannel(nameOrChannels)
稳定性: 1 - 实验性
为给定的通道创建一个 BoundedChannel 封装器。如果提供了名称,则相应的通道将以 tracing:${name}:${eventType} 的形式创建,其中 eventType 是 start 或 end。
🌐 Creates a BoundedChannel wrapper for the given channels. If a name is
given, the corresponding channels will be created in the form of
tracing:${name}:${eventType} where eventType is start or end.
BoundedChannel 是 TracingChannel 的简化版本,仅跟踪同步操作。它仅具有 start 和 end 事件,没有 asyncStart、asyncEnd 或 error 事件,因此适合跟踪不涉及异步延续或错误处理的操作。
🌐 A BoundedChannel is a simplified version of TracingChannel that only
traces synchronous operations. It only has start and end events, without
asyncStart, asyncEnd, or error events, making it suitable for tracing
operations that don't involve asynchronous continuations or error handling.
import { boundedChannel, channel } from 'node:diagnostics_channel';
const wc = boundedChannel('my-operation');
// or...
const wc2 = boundedChannel({
start: channel('tracing:my-operation:start'),
end: channel('tracing:my-operation:end'),
});const { boundedChannel, channel } = require('node:diagnostics_channel');
const wc = boundedChannel('my-operation');
// or...
const wc2 = boundedChannel({
start: channel('tracing:my-operation:start'),
end: channel('tracing:my-operation:end'),
});