program

package
v0.0.0-...-a9d0937 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunLocal

func RunLocal(ctx context.Context, routine Routine) error

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

type Routine func(ctx context.Context, siblingsGroup, dependenciesGroup Group) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL