tracingChannel.subscribe(subscribers)
稳定性: 1 - 实验性
subscribers<Object> TracingChannel 通道 个订阅者的集合start<Function>start事件 订阅者end<Function>end事件 订阅者asyncStart<Function> 该asyncStart事件 订阅者asyncEnd<Function> 该asyncEnd事件 订阅者error<Function>error活动 订阅者
用于将一组函数订阅到相应通道的助手。
这与在每个通道上单独调用 channel.subscribe(onMessage) 是一样的。
【Helper to subscribe a collection of functions to the corresponding channels.
This is the same as calling channel.subscribe(onMessage) on each channel
individually.】
import diagnostics_channel from 'node:diagnostics_channel';
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.subscribe({
start(message) {
// Handle start message
},
end(message) {
// Handle end message
},
asyncStart(message) {
// Handle asyncStart message
},
asyncEnd(message) {
// Handle asyncEnd message
},
error(message) {
// Handle error message
},
});const diagnostics_channel = require('node:diagnostics_channel');
const channels = diagnostics_channel.tracingChannel('my-channel');
channels.subscribe({
start(message) {
// Handle start message
},
end(message) {
// Handle end message
},
asyncStart(message) {
// Handle asyncStart message
},
asyncEnd(message) {
// Handle asyncEnd message
},
error(message) {
// Handle error message
},
});