channel.subscribe(onMessage)
稳定性: 0 - 已弃用:使用
diagnostics_channel.subscribe(name, onMessage)
¥Stability: 0 - Deprecated: Use diagnostics_channel.subscribe(name, onMessage)
-
onMessage
<Function> 接收通道消息的处理程序¥
onMessage
<Function> The handler to receive channel messages
注册消息处理程序以订阅此通道。每当消息发布到通道时,此消息处理程序将同步运行。消息处理程序中抛出的任何错误都将触发 'uncaughtException'
。
¥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';
const channel = diagnostics_channel.channel('my-channel');
channel.subscribe((message, name) => {
// Received data
});
const diagnostics_channel = require('node:diagnostics_channel');
const channel = diagnostics_channel.channel('my-channel');
channel.subscribe((message, name) => {
// Received data
});