概述


\Overview

以下是公共 API 的简单概述。

\Following is a simple overview of the public API.

import diagnostics_channel from 'node:diagnostics_channel';
// Get a reusable channel object
const channel = diagnostics_channel.channel('my-channel');
function onMessage(message, name) {
 // Received data
}
// Subscribe to the channel
diagnostics_channel.subscribe('my-channel', onMessage);
// Check if the channel has an active subscriber
if (channel.hasSubscribers) {
 // Publish data to the channel
 channel.publish({
 some: 'data',
 });
}
// Unsubscribe from the channel
diagnostics_channel.unsubscribe('my-channel', onMessage);const diagnostics_channel = require('node:diagnostics_channel');
// Get a reusable channel object
const channel = diagnostics_channel.channel('my-channel');
function onMessage(message, name) {
 // Received data
}
// Subscribe to the channel
diagnostics_channel.subscribe('my-channel', onMessage);
// Check if the channel has an active subscriber
if (channel.hasSubscribers) {
 // Publish data to the channel
 channel.publish({
 some: 'data',
 });
}
// Unsubscribe from the channel
diagnostics_channel.unsubscribe('my-channel', onMessage);

AltStyle によって変換されたページ (->オリジナル) /