clifecycle

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package clifecycle provides a Copper app's lifecycle management. It allows hooks to be registered that are run during various checkpoints in the app's lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lifecycle

type Lifecycle struct {
	// contains filtered or unexported fields
}

Lifecycle represents the lifecycle of an app. Most importantly, it allows various parts of the app to register stop funcs that are run before the app exits. Packages such as chttp use Lifecycle to gracefully stop the HTTP server before the app exits.

func New

func New() *Lifecycle

New instantiates and returns a new Lifecycle that can be used with New to create a Copper app.

func (*Lifecycle) OnStop

func (lc *Lifecycle) OnStop(fn func(ctx context.Context) error)

OnStop registers the provided fn to run before the app exits. The fn is given a context with a deadline. Once the deadline expires, the app may exit forcefully.

func (*Lifecycle) Stop

func (lc *Lifecycle) Stop(logger Logger)

Stop runs all of the registered stop funcs in order along with a context with a configured timeout.

type Logger

type Logger interface {
	Error(msg string, err error)
}

Logger provides the methods needed by Lifecycle to log errors.

Jump to

Keyboard shortcuts

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