Currently, the user has to write two driver loops for a petrel server:
A message handler loop, which gets launched as a goroutine
A keepalive loop, which watches the server message channel (not network messages; internal msgs) and the signal channel
This was originally done in the name of maximum flexibility, but in reality it's just boilerplate.
At the least, the keepalive loop should be handled internally and provided for free. This would include also handling SIGINT and SIGTERM. There does still need to be a way to notify the app code that petrel has errored or is shutting down -- sounds like a job for another channel, maybe, after internal housekeeping is handled?
It would be great to give users a way to not have to write the message handling loop either. Maybe if that were refactored from a function that wraps a select to an internal select that uses a dispatch table for event handling?
That way the user could register petrel event handlers the same way they register app message handlers?
Currently, the user has to write two driver loops for a petrel server:
This was originally done in the name of maximum flexibility, but in reality it's just boilerplate.
At the least, the keepalive loop should be handled internally and provided for free. This would include also handling SIGINT and SIGTERM. There does still need to be a way to notify the app code that petrel has errored or is shutting down -- sounds like a job for another channel, maybe, after internal housekeeping is handled?
It would be great to give users a way to not have to write the message handling loop either. Maybe if that were refactored from a function that wraps a
select
to an internalselect
that uses a dispatch table for event handling?That way the user could register petrel event handlers the same way they register app message handlers?