lifecycle

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package lifecycle provides a Manager that starts a set of lifecycle-managed clients in registration order and stops them in reverse for graceful shutdown, so a composition root wires its clients once and coordinates their startup and teardown centrally instead of by hand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager starts registered clients in registration order and stops them in reverse order, so dependencies come up before dependents and shut down after them. It is not safe for concurrent Register during Start/Stop; register at the composition root, then run.

func New

func New() *Manager

New returns an empty lifecycle Manager.

func (*Manager) Register

func (m *Manager) Register(name string, client interfaces.Lifecycle)

Register adds a lifecycle-managed client under a name. Registration order is the start order; the reverse is the stop order.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts every registered client in order. If one fails, the clients already started are stopped (rolled back) in reverse before the error is returned.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop stops every registered client in reverse order, continuing past failures and returning the first error encountered so shutdown always completes.

type NoOp

type NoOp struct{}

NoOp is an embeddable no-op Lifecycle for stateless clients that hold no persistent connection (SDK clients whose every call is an independent request): Start and Stop do nothing. Embed it so such a client satisfies interfaces.Lifecycle without re-declaring the identical no-op methods on each backend.

func (NoOp) Start

func (NoOp) Start(context.Context) error

Start is a no-op: a stateless client has no resource to open.

func (NoOp) Stop

func (NoOp) Stop(context.Context) error

Stop is a no-op: a stateless client has no resource to close.

Jump to

Keyboard shortcuts

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