| | |
| | | * should generally include the module name to avoid collisions with data from |
| | | * other modules. |
| | | * @experimental |
| | | * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/diagnostics_channel.js) |
| | | * @see [source](https://github.com/nodejs/node/blob/v17.0.0/lib/diagnostics_channel.js) |
| | | */ |
| | | declare module 'diagnostics_channel' { |
| | | /** |
| | |
| | | * @return The named channel object |
| | | */ |
| | | function channel(name: string): Channel; |
| | | type ChannelListener = (name: string, message: unknown) => void; |
| | | type ChannelListener = (message: unknown, name: string) => void; |
| | | /** |
| | | * The class `Channel` represents an individual named channel within the data |
| | | * pipeline. It is use to track subscribers and to publish messages when there |
| | |
| | | readonly hasSubscribers: boolean; |
| | | private constructor(name: string); |
| | | /** |
| | | * Publish a message to any subscribers to the channel. This will |
| | | * trigger message handlers synchronously so they will execute within |
| | | * the same context. |
| | | * |
| | | * ```js |
| | | * import diagnostics_channel from 'diagnostics_channel'; |
| | | * |
| | | * const channel = diagnostics_channel.channel('my-channel'); |
| | | * |
| | | * channel.publish({ |
| | | * some: 'message' |
| | | * }); |
| | | * ``` |
| | | * @since v15.1.0, v14.17.0 |
| | | * @param message The message to send to the channel subscribers |
| | | */ |
| | | publish(message: unknown): void; |
| | | /** |
| | | * 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'`. |