Skip to content

Exports

[<Class>]
type Exports =
    static member TracingChannel<'StoreType, 'ContextType> () : TracingChannel<'StoreType,'ContextType>
    static member channel (name: U2<string,Symbol>) : Channel<obj,obj>
    static member hasSubscribers (name: U2<string,Symbol>) : bool
    static member subscribe (name: U2<string,Symbol>, onMessage: ChannelListener) : unit
    static member tracingChannel<'StoreType, 'ContextType> (nameOrChannels: U2<string,TracingChannelCollection<'StoreType,'ContextType>>) : TracingChannel<'StoreType,'ContextType>
    static member unsubscribe (name: U2<string,Symbol>, onMessage: ChannelListener) : bool
AssemblyXantham.Fable.Node
Attributes[<Erase>]

The package's value exports, each bound to its import.

Methods

static member TracingChannel<'StoreType, 'ContextType> () : TracingChannel<'StoreType,'ContextType>

The class TracingChannel is a collection of TracingChannel Channels which together express a single traceable action. It is used to formalize and simplify the process of producing events for tracing application flow. tracingChannel is used to construct a TracingChannel. As with Channel it is recommended to create and reuse a single TracingChannel at the top-level of the file rather than creating them dynamically.

@since v19.9.0

static member channel (name: U2<string,Symbol>) : Channel<obj,obj>

This is the primary entry-point for anyone wanting to publish to a named channel. It produces a channel object which is optimized to reduce overhead at publish time as much as possible.

import diagnostics_channel from 'node:diagnostics_channel';

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

@since v15.1.0, v14.17.0

Parameter
nameThe channel name

Returns. The named channel object

static member hasSubscribers (name: U2<string,Symbol>) : bool

Check if there are active subscribers to the named channel. This is helpful if the message you want to send might be expensive to prepare.

This API is optional but helpful when trying to publish messages from very performance-sensitive code.

import diagnostics_channel from 'node:diagnostics_channel';

if (diagnostics_channel.hasSubscribers('my-channel')) {
// There are subscribers, prepare and publish message
}

@since v15.1.0, v14.17.0

Parameter
nameThe channel name

Returns. If there are active subscribers

static member subscribe (name: U2<string,Symbol>, onMessage: ChannelListener) : unit

Register a message handler to subscribe to this channel. This message handler will be run synchronously whenever a message is published to the channel. Any errors thrown in the message handler will trigger an 'uncaughtException'.

import diagnostics_channel from 'node:diagnostics_channel';

diagnostics_channel.subscribe('my-channel', (message, name) => {
// Received data
});

@since v18.7.0, v16.17.0

Parameter
nameThe channel name
onMessageThe handler to receive channel messages
static member tracingChannel<'StoreType, 'ContextType> (nameOrChannels: U2<string,TracingChannelCollection<'StoreType,'ContextType>>) : TracingChannel<'StoreType,'ContextType>

Creates a TracingChannel wrapper for the given TracingChannel Channels. If a name is given, the corresponding tracing channels will be created in the form of tracing:${name}:${eventType} where eventType corresponds to the types of TracingChannel Channels.

import diagnostics_channel from 'node:diagnostics_channel';

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

// or...

const channelsByCollection = diagnostics_channel.tracingChannel({
start: diagnostics_channel.channel('tracing:my-channel:start'),
end: diagnostics_channel.channel('tracing:my-channel:end'),
asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'),
asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'),
error: diagnostics_channel.channel('tracing:my-channel:error'),
});

@since v19.9.0

Parameter
nameOrChannelsChannel name or object containing all the TracingChannel Channels

Returns. Collection of channels to trace with

static member unsubscribe (name: U2<string,Symbol>, onMessage: ChannelListener) : bool

Remove a message handler previously registered to this channel with subscribe.

import diagnostics_channel from 'node:diagnostics_channel';

function onMessage(message, name) {
// Received data
}

diagnostics_channel.subscribe('my-channel', onMessage);

diagnostics_channel.unsubscribe('my-channel', onMessage);

@since v18.7.0, v16.17.0

Parameter
nameThe channel name
onMessageThe previous subscribed handler to remove

Returns. true if the handler was found, false otherwise.