Mrun
Bun

method

diagnostics_channel.BoundedChannel.run

run<ThisArg = any, Args extends any[] = any[], Result = any>(
fn: (this: ThisArg, ...args: Args) => Result,
context?: ContextType,
thisArg?: ThisArg,
...args: Args
): Result;

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;
});
@param fn

Function to wrap a trace around

@param context

Shared object to correlate events through

@param thisArg

The receiver to be used for the function call

@param args

Optional arguments to pass to the function

@returns

The return value of the given function