lifecycle

package
v0.3.0-20260807201250-... Latest Latest
Warning

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

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

Documentation

Overview

Package lifecycle provides the Component interface and Group type for managing ordered start/stop lifecycles. Every runnable subsystem (consumer, publisher, server) implements Component; Group composes them into a single Component with deterministic ordering and rollback on partial failure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	// Start initializes and starts the component. The context governs the
	// start-up phase (e.g. connecting, subscribing); long-running work may
	// outlive the context and must be terminated by calling Stop.
	Start(ctx context.Context) error

	// Stop gracefully shuts down the component. The context provides a
	// deadline for the shutdown; implementations should respect it and
	// return promptly when the context is cancelled.
	Stop(ctx context.Context) error
}

Component is anything with a lifecycle. Construct returns one; hosts drive it.

type Group

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

Group runs an ordered list of Components as one Component.

  • Start: members in order; if member i fails to start, members i-1…0 are stopped in reverse and the error is returned — no half-started state.
  • Stop: members in REVERSE order (work-acceptors drain before the connections under them close); errors joined, none swallowed.

func NewGroup

func NewGroup(members ...Component) *Group

NewGroup creates a Group from the given components. Nil members are silently skipped so callers can pass optional components without nil-checking.

func (*Group) Start

func (g *Group) Start(ctx context.Context) error

Start starts all members in order. If any member fails to start, all previously started members are stopped in reverse order and the original start error is returned. The stop errors from rollback, if any, are joined with the start error.

func (*Group) Stop

func (g *Group) Stop(ctx context.Context) error

Stop stops all members in reverse order. All stop errors are joined so none is swallowed; a single member's failure does not prevent the others from being stopped.

Jump to

Keyboard shortcuts

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