shutdown

package
v1.7.19 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrShutdown = errors.New("shutdown")

ErrShutdown is the error condition when a context has been fully shutdown

Functions

This section is empty.

Types

type Service

type Service interface {
	// Shutdown initiates shutdown
	Shutdown()
	// RegisterCallback registers functions to be called on shutdown and before
	// the shutdown channel is closed. A callback error will propagate to the
	// context error
	RegisterCallback(func(context.Context) error)
	// Done returns a channel that's closed when all shutdown callbacks are invoked.
	Done() <-chan struct{}
	// Err returns nil if Done is not yet closed.
	// If Done is closed, Err returns first failed callback error or ErrShutdown.
	Err() error
}

Service is used to facilitate shutdown by through callback registration and shutdown initiation

func WithShutdown

func WithShutdown(ctx context.Context) (context.Context, Service)

WithShutdown returns a context which is similar to a cancel context, but with callbacks which can propagate to the context error. Unlike a cancel context, the shutdown context cannot be canceled from the parent context. However, future child contexes will be canceled upon shutdown.

Jump to

Keyboard shortcuts

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