How run.Group manages goroutine lifecycles
mainA run.Group is a mechanism to orchestrate multiple goroutines as a single unit. You manage lifecycles by adding actors to a zero-value run.Group.
An actor consists of two functions:
- An execute function: This function runs synchronously within its own goroutine.
- An interrupt function: This function is called when any actor in the group exits. Its purpose is to signal the execute function to return (e.g., by closing a connection or canceling a context).
When you call Run(), the group concurrently executes all actors. The group waits until the first actor exits, then invokes the interrupt functions for all other actors. Run() only returns to the caller once all actors have fully returned.