lifecycle

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callable added in v1.19.0

type Callable interface {
	~Func | ~ErrorFunc | ~ContextFunc | ~ContextErrorFunc
}

A Callable is a constraint that matches functions that are, or can be converted to, functions suitable for a Hook.

Callable must be identical to [fx.HookFunc].

type ContextErrorFunc added in v1.19.0

type ContextErrorFunc = func(context.Context) error

A ContextErrorFunc is used as a [Hook.OnStart] or [Hook.OnStop] function.

func Wrap added in v1.19.0

func Wrap[T Callable](x T) (ContextErrorFunc, string)

Wrap wraps x into a ContextErrorFunc suitable for a Hook.

type ContextFunc added in v1.19.0

type ContextFunc = func(context.Context)

A ContextFunc can be converted to a ContextErrorFunc.

type ErrorFunc added in v1.19.0

type ErrorFunc = func() error

An ErrorFunc can be converted to a ContextErrorFunc.

type Func added in v1.19.0

type Func = func()

A Func can be converted to a ContextErrorFunc.

type Hook

type Hook struct {
	OnStart     func(context.Context) error
	OnStop      func(context.Context) error
	OnStartName string
	OnStopName  string
	// contains filtered or unexported fields
}

A Hook is a pair of start and stop callbacks, either of which can be nil, plus a string identifying the supplier of the hook.

type HookRecord added in v1.14.0

type HookRecord struct {
	CallerFrame fxreflect.Frame             // stack frame of the caller
	Func        func(context.Context) error // function that ran as sanitized name
	Runtime     time.Duration               // how long the hook ran
}

HookRecord keeps track of each Hook's execution time, the caller that appended the Hook, and function that ran as the Hook.

type HookRecords added in v1.14.0

type HookRecords []HookRecord

HookRecords is a Stringer wrapper of HookRecord slice.

func (HookRecords) Format added in v1.14.0

func (rs HookRecords) Format(w fmt.State, c rune)

Format implements fmt.Formatter to handle "%+v".

func (HookRecords) Len added in v1.14.0

func (rs HookRecords) Len() int

func (HookRecords) Less added in v1.14.0

func (rs HookRecords) Less(i, j int) bool

func (HookRecords) String added in v1.14.0

func (rs HookRecords) String() string

Used for logging startup errors.

func (HookRecords) Swap added in v1.14.0

func (rs HookRecords) Swap(i, j int)

type Lifecycle

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

Lifecycle coordinates application lifecycle hooks.

func New

func New(logger fxevent.Logger, clock fxclock.Clock) *Lifecycle

New constructs a new Lifecycle.

func (*Lifecycle) Append

func (l *Lifecycle) Append(hook Hook)

Append adds a Hook to the lifecycle.

func (*Lifecycle) RunningHookCaller added in v1.14.0

func (l *Lifecycle) RunningHookCaller() string

RunningHookCaller returns the name of the hook that was running when a Start/Stop hook timed out.

func (*Lifecycle) Start

func (l *Lifecycle) Start(ctx context.Context) error

Start runs all OnStart hooks, returning immediately if it encounters an error.

func (*Lifecycle) Stop

func (l *Lifecycle) Stop(ctx context.Context) error

Stop runs any OnStop hooks whose OnStart counterpart succeeded. OnStop hooks run in reverse order.

Jump to

Keyboard shortcuts

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