boot

package
v0.16.2 Latest Latest
Warning

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

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

Documentation

Overview

Package boot starts components in dataflow order and passes their outputs to downstream components once startup succeeds.

This is not a dynamic graph. It validates and starts one fixed set of components. Do any work that decides which components should participate up front, before the graph starts. Startup makes one forward pass, running independent components in parallel. Shutdown follows the same dataflow edges in reverse. The graph does not restart anything or run startup again.

Use ProvideN for a component that publishes a value to downstream work. Its start callback must not return until that value is ready to use; the graph can order callback completion, but it cannot infer what readiness means for the value. Use RunN for side-effect-only work. A dependent component can name that work with DependsOn when it needs completion but no value from it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Provide0

func Provide0[O any](name string, start func(context.Context) (O, error), options ...Option) (*Component, Output[O])

func Provide1

func Provide1[A, O any](name string, a Output[A], start func(context.Context, A) (O, error), options ...Option) (*Component, Output[O])

func Provide2

func Provide2[A, B, O any](name string, a Output[A], b Output[B], start func(context.Context, A, B) (O, error), options ...Option) (*Component, Output[O])

func Provide3

func Provide3[A, B, C, O any](name string, a Output[A], b Output[B], c Output[C], start func(context.Context, A, B, C) (O, error), options ...Option) (*Component, Output[O])

func Provide4

func Provide4[A, B, C, D, O any](name string, a Output[A], b Output[B], c Output[C], d Output[D], start func(context.Context, A, B, C, D) (O, error), options ...Option) (*Component, Output[O])

func Provide5

func Provide5[A, B, C, D, E, O any](name string, a Output[A], b Output[B], c Output[C], d Output[D], e Output[E], start func(context.Context, A, B, C, D, E) (O, error), options ...Option) (*Component, Output[O])

func Provide6

func Provide6[A, B, C, D, E, F, O any](name string, a Output[A], b Output[B], c Output[C], d Output[D], e Output[E], f Output[F], start func(context.Context, A, B, C, D, E, F) (O, error), options ...Option) (*Component, Output[O])

func Provide7

func Provide7[A, B, C, D, E, F, G, O any](name string, a Output[A], b Output[B], c Output[C], d Output[D], e Output[E], f Output[F], g Output[G], start func(context.Context, A, B, C, D, E, F, G) (O, error), options ...Option) (*Component, Output[O])

Types

type Component

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

Component defines one participant in the boot dataflow graph.

func Run0

func Run0(name string, start func(context.Context) error, options ...Option) *Component

func Run1

func Run1[A any](name string, a Output[A], start func(context.Context, A) error, options ...Option) *Component

func Run2

func Run2[A, B any](name string, a Output[A], b Output[B], start func(context.Context, A, B) error, options ...Option) *Component

func Run3

func Run3[A, B, C any](name string, a Output[A], b Output[B], c Output[C], start func(context.Context, A, B, C) error, options ...Option) *Component

func Run4

func Run4[A, B, C, D any](name string, a Output[A], b Output[B], c Output[C], d Output[D], start func(context.Context, A, B, C, D) error, options ...Option) *Component

func Run5

func Run5[A, B, C, D, E any](name string, a Output[A], b Output[B], c Output[C], d Output[D], e Output[E], start func(context.Context, A, B, C, D, E) error, options ...Option) *Component

func Run6

func Run6[A, B, C, D, E, F any](name string, a Output[A], b Output[B], c Output[C], d Output[D], e Output[E], f Output[F], start func(context.Context, A, B, C, D, E, F) error, options ...Option) *Component

func Run7

func Run7[A, B, C, D, E, F, G any](name string, a Output[A], b Output[B], c Output[C], d Output[D], e Output[E], f Output[F], g Output[G], start func(context.Context, A, B, C, D, E, F, G) error, options ...Option) *Component

func (*Component) String

func (c *Component) String() string

type Graph

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

Graph owns component startup and reverse shutdown ordering.

func NewGraph

func NewGraph() *Graph

NewGraph creates an empty boot graph.

func (*Graph) Add

func (g *Graph) Add(component *Component) error

Add registers a component with the graph. All components must be added before Validate or Start is called.

func (*Graph) Start

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

Start validates the graph, starts independent components concurrently, and waits until every component has returned successfully.

func (*Graph) Stop

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

Stop stops successfully started components in reverse dataflow order.

func (*Graph) Validate

func (g *Graph) Validate() error

Validate checks input producers and cycles without starting anything.

type Option

type Option func(*Component)

Option adds dependencies or lifecycle behavior to a component.

func DependsOn

func DependsOn(dependencies ...*Component) Option

DependsOn adds order-only edges to a component. Use it when startup must wait for side-effect-only work that has no value to publish.

func WithStop

func WithStop(stop StopFunc, timeout time.Duration) Option

WithStop adds a stop function and its component-specific timeout. A zero timeout uses the Graph.Stop caller's context directly.

type Output

type Output[T any] struct {
	// contains filtered or unexported fields
}

Output is a ready-to-use value published after its producer starts successfully.

func ResolvedOutput

func ResolvedOutput[T any](value T) Output[T]

ResolvedOutput returns an already-published value for focused component tests that do not assemble a graph.

func (Output[T]) Value

func (o Output[T]) Value() T

Value returns a published output for callers outside the boot graph, such as the owner collecting top-level services after Graph.Start. Component start callbacks receive resolved values directly and do not need to call Value.

type StopFunc

type StopFunc func(context.Context) error

StopFunc stops a component.

Jump to

Keyboard shortcuts

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