You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have this pattern where I have a main goroutine which is accompanied/supported by side goroutines. The main goroutines produces a value, whereas the side goroutines do not produce any values to capture but perform some sort of upkeep or utility function. Once the main goroutine exits, the side goroutines' context should be canceled. If the side goroutines exit with an error or panic, the main and other side goroutines should be canceled.
An example of where I use this pattern is inside of gRPC server-streaming handlers. I send a keep alive message on a regular interval to keep the connection alive while the main goroutine is waiting on an event to happen. Once the main goroutine is done I want to kill the keep-alive routine obviously.
Naming is hard, I'm calling this the daemon/sidekick pattern for now, similar to daemon threads in Python. It's also kind of similar to sidecar pods in Kubernetes.
Right now Pool.Wait waits for all the routines to be done, if there was a way to wait only for the first routine to be finished and cancel the others, this pattern could be achieved easily.
Is there interest in adding feature support for this?
The text was updated successfully, but these errors were encountered:
I have this pattern where I have a main goroutine which is accompanied/supported by side goroutines. The main goroutines produces a value, whereas the side goroutines do not produce any values to capture but perform some sort of upkeep or utility function. Once the main goroutine exits, the side goroutines' context should be canceled. If the side goroutines exit with an error or panic, the main and other side goroutines should be canceled.
An example of where I use this pattern is inside of gRPC server-streaming handlers. I send a keep alive message on a regular interval to keep the connection alive while the main goroutine is waiting on an event to happen. Once the main goroutine is done I want to kill the keep-alive routine obviously.
Naming is hard, I'm calling this the daemon/sidekick pattern for now, similar to daemon threads in Python. It's also kind of similar to sidecar pods in Kubernetes.
I have a basic implementation of this here https://github.com/sbstp/unison/blob/master/sidekick.go but it's a bit primitive and doesn't print panics cleanly.
Right now Pool.Wait waits for all the routines to be done, if there was a way to wait only for the first routine to be finished and cancel the others, this pattern could be achieved easily.
Is there interest in adding feature support for this?
The text was updated successfully, but these errors were encountered: