类:BoundedChannelScope
🌐 Class: BoundedChannelScope
稳定性: 1 - 实验性
类 BoundedChannelScope 表示由 boundedChannel.withScope(context) 创建的可释放范围。它管理被跟踪操作的生命周期,自动发布事件并管理存储上下文。
🌐 The class BoundedChannelScope represents a disposable scope created by
boundedChannel.withScope(context). It manages the lifecycle of a traced
operation, automatically publishing events and managing store contexts.
必须将作用域与 using 语法一起使用以确保适当的处置。
🌐 The scope must be used with the using syntax to ensure proper disposal.
import { boundedChannel } from 'node:diagnostics_channel';
const wc = boundedChannel('my-operation');
const context = {};
{
using scope = wc.withScope(context);
// Start event is published, stores are entered
context.result = performOperation();
// End event is automatically published at end of block
}const { boundedChannel } = require('node:diagnostics_channel');
const wc = boundedChannel('my-operation');
const context = {};
{
using scope = wc.withScope(context);
// Start event is published, stores are entered
context.result = performOperation();
// End event is automatically published at end of block
}