Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Daemon/Sidekick Pool #141

Open
sbstp opened this issue Sep 6, 2024 · 0 comments
Open

Feature Request: Daemon/Sidekick Pool #141

sbstp opened this issue Sep 6, 2024 · 0 comments

Comments

@sbstp
Copy link

sbstp commented Sep 6, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant