Skip to main content
Channel.prototype.bindStore - diagnostics_channel - Node documentation
method Channel.prototype.bindStore
Unstable

Usage in Deno

import { Channel } from "node:diagnostics_channel";
Channel.prototype.bindStore(
store: AsyncLocalStorage<StoreType>,
transform?: (context: ContextType) => StoreType,
): void

When channel.runStores(context, ...) is called, the given context data will be applied to any store bound to the channel. If the store has already been bound the previous transform function will be replaced with the new one. The transform function may be omitted to set the given context data as the context directly.

import diagnostics_channel from 'node:diagnostics_channel';
import { AsyncLocalStorage } from 'node:async_hooks';

const store = new AsyncLocalStorage();

const channel = diagnostics_channel.channel('my-channel');

channel.bindStore(store, (data) => {
  return { data };
});

Parameters

store: AsyncLocalStorage<StoreType>

The store to which to bind the context data

optional
transform: (context: ContextType) => StoreType

Transform context data before setting the store context

Return Type

void