Help us shape the future of Go! Take the 2026 Go Developer Survey

lifecycle

package
v0.36.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package lifecycle runs the platform's providers through boot and stop in one order (ADR-0305). A provider implements Provider and any of Starter, Reclaimer, Runner, BeforeStopper and Stopper; Phases runs each hook a provider has: Start, then Reclaim, in list order at boot, Run once every Start passed, BeforeStop and Stop in reverse at stop. It follows the idiom of the invoke chain (ADR-0302): a required interface, and optional ones a type assertion finds. A shared hook is such an optional interface of the package that builds the list, walked with Each and named in the boot log with Named (ADR-0308).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Each

func Each[H Provider](ph *Phases) []H

Each returns the providers that implement H, in list order: the walk a shared hook of another package runs.

Types

type BeforeStopper

type BeforeStopper interface {
	Provider
	BeforeStop(ctx context.Context) error
}

BeforeStopper runs when the daemon is about to close, before any provider stops.

type Hook

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

Hook is an optional provider interface under its boot-log name.

func Named

func Named[H Provider](name string) Hook

Named is the hook H, logged as name.

type Phases

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

Phases runs the hooks of its providers in their order. BeforeStop and Stop run for every provider, booted or not, so each must be safe when its Start never ran or failed: a New that fails stops the platform it was building, and a failed Start stops the providers after it too. It is safe for concurrent use; once stopping has begun, Start, Reclaim and Run start no further provider.

func New

func New(providers ...Provider) *Phases

New returns the phases of providers, in their boot order.

func (*Phases) BeforeStop

func (ph *Phases) BeforeStop(ctx context.Context) error

BeforeStop runs every BeforeStopper in reverse order and joins their errors.

func (*Phases) Hooks

func (ph *Phases) Hooks(shared ...Hook) []string

Hooks names each provider with the hooks it has, then each of shared it implements, in list order, for the boot log: "executor: start, run, before stop, stop".

func (*Phases) Providers

func (ph *Phases) Providers() []Provider

Providers returns the providers in list order.

func (*Phases) Reclaim

func (ph *Phases) Reclaim(ctx context.Context) error

Reclaim runs each Reclaimer in list order and joins their errors, naming each provider.

func (*Phases) Run

func (ph *Phases) Run(ctx context.Context, wg *sync.WaitGroup)

Run starts each Runner on ctx in its own goroutine, counted in wg, unless stopping has begun.

func (*Phases) Start

func (ph *Phases) Start(ctx context.Context) error

Start runs each Starter in list order and returns the first error, naming its provider.

func (*Phases) Stop

func (ph *Phases) Stop(ctx context.Context) error

Stop runs every Stopper in reverse order and joins their errors.

type Provider

type Provider interface {
	Name() string
}

Provider is one platform provider; it also implements none or more of Starter, Reclaimer, Runner, BeforeStopper and Stopper.

type Reclaimer

type Reclaimer interface {
	Provider
	Reclaim(ctx context.Context) error
}

Reclaimer reclaims at boot, after every Start, what its provider's resources deleted before their reconcile ran still hold (ADR-0307). The platform runs it only on a boot that is not held (ADR-0206 Decision 6).

type Runner

type Runner interface {
	Provider
	Run(ctx context.Context)
}

Runner runs a provider's long-running work on the platform's run context, from after every Start until that context ends. The platform waits for it with its own loops, before any provider stops.

type Starter

type Starter interface {
	Provider
	Start(ctx context.Context) error
}

Starter starts a provider at boot, before the platform starts its own loops. An error ends the boot there.

type Stopper

type Stopper interface {
	Provider
	Stop(ctx context.Context) error
}

Stopper releases what a provider holds.

Jump to

Keyboard shortcuts

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