Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunLocal ¶
RunLocal runs a set of goroutines until completion. This function provides the same functionality as errgroup.Group, with a couple of differences:
There is no need to call a separate Wait() function. This prevents leaking Context objects by accident.
Like RunMain(), routines are placed in a hierarchy of siblings and dependencies, making it easier to trigger shutdown.
func RunMain ¶
func RunMain(routine Routine)
RunMain runs a program that supports graceful termination. Programs consist of a pool of routines that may have dependencies on each other. Programs terminate if one of the following three cases occur:
The root routine and all of its siblings have terminated. In that case the program terminates with exit code 0.
One of the routines fails with a non-nil error. In that case the program terminates with exit code 1.
The program receives SIGINT or SIGTERM. In that case the program will terminate with that signal.
In case termination occurs, all remaining routines are canceled, respecting dependencies between these routines. This can for example be used to ensure an outgoing database connection is terminated after an integrated RPC server is shut down.
Types ¶
type Group ¶
type Group interface {
Go(routine Routine)
}
Group of routines. This interface can be used to launch additional routines.
type Routine ¶
Routine that can be executed as part of a program. Routines may include web/gRPC servers, storage flushing processes or clients that repeatedly perform requests against a remote service.
Each routine is capable of launching additional routines that either run as siblings, or as dependencies of the current routine and its siblings. Siblings are all terminated at the same time, while dependencies are only terminated after all of the siblings of the current routine have completed.