Skip to content

Feature Request: Daemon/Sidekick Pool  #141

@sbstp

Description

@sbstp

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions