pino icon indicating copy to clipboard operation
pino copied to clipboard

Allow worker thread to emit custom event back to parent

Open TAYTS opened this issue 3 years ago • 5 comments

The current worker thread only allow event with "READY" and "ERROR" and any other events will get remove. Wonder if it is possible to allow other event to propagate back instead of stripping off?

The current use case is to allow propagation of error object back to the main process but when we emit "error" event or throw error the worker thread will terminate immediately which will cause the main process to terminate for subsequent logging attempt.

https://github.com/pinojs/thread-stream/blob/main/index.js#L138-L164

TAYTS avatar Feb 18 '22 02:02 TAYTS

What other signals do logger threads need?

jsumners avatar Feb 18 '22 02:02 jsumners

Sorry for the late reply, was thinking adding a new signal "MESSAGE" to have the flexibility to allow worker thread to communicate with the parent instead of one way communicate, although I am not sure if this is against the Pino's design philosophy.

The other option I have is to allow to have some flag along with the "ERROR" signal to prevent the stream being destroyed as currently whenever the stream emit an error, the stream will get destroy. Thought it could be useful to post the non-destructive error signal back to the parent.

TAYTS avatar Feb 25 '22 05:02 TAYTS

What are the use cases for these changes?

jsumners avatar Feb 25 '22 13:02 jsumners

@TAYTS Did you manage to resolve this?

Fdawgs avatar May 29 '23 09:05 Fdawgs

I've had success with this by posting an object message with the code property set to 'EVENT' and set an arbitrary name property and any data I need passed to the data property

hazelnutcloud avatar Dec 19 '23 14:12 hazelnutcloud