channel.unsubscribe(onMessage)


版本历史
版本变更
v22.20.0

弃用已撤销。

v18.7.0, v16.17.0

仅文档弃用。

v17.1.0, v16.14.0, v14.19.0

附加的返回值。添加到没有订阅者的通道。

v15.1.0, v14.17.0

新增于: v15.1.0, v14.17.0

  • onMessage <Function> 要删除的先前订阅的处理程序

    \onMessage <Function> The previous subscribed handler to remove

  • 返回:<boolean> 如果找到处理程序则为 true,否则为 false

    \Returns: <boolean> true if the handler was found, false otherwise.

删除以前使用 channel.subscribe(onMessage) 注册到此通道的消息处理程序。

\Remove a message handler previously registered to this channel with channel.subscribe(onMessage).

import diagnostics_channel from 'node:diagnostics_channel';
const channel = diagnostics_channel.channel('my-channel');
function onMessage(message, name) {
 // Received data
}
channel.subscribe(onMessage);
channel.unsubscribe(onMessage);const diagnostics_channel = require('node:diagnostics_channel');
const channel = diagnostics_channel.channel('my-channel');
function onMessage(message, name) {
 // Received data
}
channel.subscribe(onMessage);
channel.unsubscribe(onMessage);

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