Bun

interface

diagnostics_channel.BoundedChannelScope

interface BoundedChannelScope

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.

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
}