lifecycle

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	Name() string
	Start(ctx context.Context, wg *sync.WaitGroup) error
	Stop(ctx context.Context) error
}

Component represents a startable/stoppable application component.

func NewSimpleComponent

func NewSimpleComponent(name string, s Startable) Component

NewSimpleComponent creates a Component adapter from a Startable.

type ComponentEntry

type ComponentEntry struct {
	Component Component
	Priority  Priority
}

ComponentEntry pairs a component with its startup priority.

type ErrorComponent

type ErrorComponent struct {
	ComponentName string
	StartFunc     func(ctx context.Context) error
	StopFunc      func()
}

ErrorComponent adapts components with Start(context.Context) error / Stop() signatures.

func (*ErrorComponent) Name

func (c *ErrorComponent) Name() string

func (*ErrorComponent) Start

func (c *ErrorComponent) Start(ctx context.Context, _ *sync.WaitGroup) error

func (*ErrorComponent) Stop

func (c *ErrorComponent) Stop(_ context.Context) error

type FuncComponent

type FuncComponent struct {
	ComponentName string
	StartFunc     func(ctx context.Context, wg *sync.WaitGroup) error
	StopFunc      func(ctx context.Context) error
}

FuncComponent wraps arbitrary start/stop functions.

func NewFuncComponent

func NewFuncComponent(
	name string,
	startFn func(ctx context.Context, wg *sync.WaitGroup) error,
	stopFn func(ctx context.Context) error,
) *FuncComponent

NewFuncComponent creates a Component from start/stop functions.

func (*FuncComponent) Name

func (c *FuncComponent) Name() string

func (*FuncComponent) Start

func (c *FuncComponent) Start(ctx context.Context, wg *sync.WaitGroup) error

func (*FuncComponent) Stop

func (c *FuncComponent) Stop(ctx context.Context) error

type Priority

type Priority int

Priority controls component startup order (lower = earlier).

const (
	PriorityInfra      Priority = 100
	PriorityCore       Priority = 200
	PriorityBuffer     Priority = 300
	PriorityNetwork    Priority = 400
	PriorityAutomation Priority = 500
)

type Registry

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

Registry manages component lifecycle with ordered startup and reverse shutdown.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty component registry.

func (*Registry) Len

func (r *Registry) Len() int

Len returns the number of registered components.

func (*Registry) Names added in v0.6.0

func (r *Registry) Names() []string

Names returns the names of all registered components in registration order.

func (*Registry) Register

func (r *Registry) Register(c Component, p Priority)

Register adds a component at the given priority.

func (*Registry) StartAll

func (r *Registry) StartAll(ctx context.Context, wg *sync.WaitGroup) error

StartAll starts all registered components in priority order (ascending). If a component fails to start, already-started components are stopped in reverse order (rollback).

func (*Registry) StopAll

func (r *Registry) StopAll(ctx context.Context) error

StopAll stops all started components in reverse startup order.

type SimpleComponent

type SimpleComponent struct {
	ComponentName string
	StartFunc     func(wg *sync.WaitGroup)
	StopFunc      func()
}

SimpleComponent adapts components with Start(*sync.WaitGroup) / Stop() signatures.

func (*SimpleComponent) Name

func (c *SimpleComponent) Name() string

func (*SimpleComponent) Start

func (*SimpleComponent) Stop

func (c *SimpleComponent) Stop(_ context.Context) error

type Startable

type Startable interface {
	Start(wg *sync.WaitGroup)
	Stop()
}

Startable represents components with Start(*sync.WaitGroup) / Stop() signatures.

Jump to

Keyboard shortcuts

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