subscribe

external fun subscribe(name: String, onMessage: ChannelListener)(source)
external fun subscribe(name: Symbol, onMessage: ChannelListener)(source)

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

Parameters

name

The channel name

onMessage

The handler to receive channel messages