lifecycle

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package lifecycle manages explicit startup and reverse-order shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(resource any) (func(context.Context) error, error)

Cleanup adapts HTTP/gRPC servers, workers, telemetry providers, Kafka producers/consumers, SQL/Redis clients and log outputs. The resulting function is idempotent; a deadline can stop waiting without losing the ability to await ongoing cleanup again.

func NotifyContext

func NotifyContext(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelFunc)

NotifyContext explicitly opts into OS signal handling. The caller must invoke stop.

Types

type Hook

type Hook struct {
	Name  string
	Start func(context.Context) error
	Stop  func(context.Context) error
}

Hook describes an explicit lifecycle action or instrumentation callback.

type Manager

type Manager struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

Manager serializes lifecycle operations. Hooks must respect their context.

func (*Manager) Register

func (m *Manager) Register(h Hook) error

Register registers a named hook or check before use.

func (*Manager) RegisterResource

func (m *Manager) RegisterResource(name string, factory func(context.Context) (any, error)) error

RegisterResource initializes an owned resource in startup order and closes it in reverse order. A factory that returns both a resource and an error has that partial resource cleaned up before the error is returned.

func (*Manager) Start

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

Start starts registered work with the supplied context.

func (*Manager) Stop

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

Stop stops owned work in documented cleanup order.

Jump to

Keyboard shortcuts

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