Documentation
¶
Overview ¶
Package lifecycle provides structured management of service and goroutine lifecycles. It coordinates ordered startup and graceful shutdown of components, ensuring proper initialization sequence and reverse-order cleanup.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Component ¶
type Component interface { // Start is called during startup. // Returning an error or calling cancel will initiate shutdown. Start(ctx context.Context, cancel context.CancelCauseFunc) error // Stop is called during shutdown. Stop(ctx context.Context) error }
Component represents a component that can be managed by Lifecycle.
type Lifecycle ¶
type Lifecycle struct {
// contains filtered or unexported fields
}
Lifecycle manages component initialization and shutdown. Starts components in append order, stops them in reverse order.
type Option ¶
type Option func(cfg *config)
Option represents Lifecycle configuration option.
func WithLogger ¶
WithLogger sets the logger for lifecycle events. Default is none.
func WithStopTimeout ¶
WithStopTimeout sets shutdown timeout duration. Default is one minute.
type Procedure ¶
type Procedure struct { // The name of the procedure. Used in logging. Name string // OnStart is called during startup. OnStart func(ctx context.Context) error // OnStop is called during shutdown. OnStop func(ctx context.Context) error }
Procedure runs OnStart and OnStop functions during startup/shutdown. If OnStart function returns an error, shutdown will be initiated.
type Service ¶
type Service struct { // The name of the service. Used in logging. Name string // Run is called inside a goroutine during startup. Run func(ctx context.Context) error // Shutdown is called during shutdown. Shutdown func(ctx context.Context) error }
Service runs Run function in a goroutine during startup and Shutdown function during shutdown. If Run function returns an error, shutdown will be initiated.
type SignalError ¶
func (*SignalError) Error ¶
func (e *SignalError) Error() string