Documentation
¶
Overview ¶
Package lifecycle coordinates an ordered tree of application components. Start runs parent hooks before children, in creation order. Stop unwinds children in reverse order, then cancels the node, runs its stop hooks in reverse order and drains its goroutines. A failed start is unwound too. Call Stop even when Start fails. Hooks must honor their context deadlines.
Node lifetimes are detached from the startup context, so shutdown can drain dependents before closing their dependencies. No signals, logging or health policy is imposed. The application drives Start, Failed and Stop.
Index ¶
- Variables
- type Group
- type Node
- func (n *Node) Budget(fn func(ctx context.Context) (context.Context, context.CancelFunc))
- func (n *Node) Child(name string) *Node
- func (n *Node) Children() []*Node
- func (n *Node) Failed() <-chan error
- func (n *Node) Go(fn func(ctx context.Context) error)
- func (n *Node) Name() string
- func (n *Node) OnStart(fn func(ctx context.Context) error)
- func (n *Node) OnStop(fn func(ctx context.Context) error)
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Stop(ctx context.Context) error
- func (n *Node) Walk(fn func(*Node))
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node owns start/stop hooks and goroutines. It must not be copied. Create a root with New and declare its children before Start. A starting node may also create children in its own start hooks. Start and Stop are serialized across the tree; they must not be called from a lifecycle hook.
func (*Node) Budget ¶
Budget narrows the node's own stop (its stop hooks and the wait for its goroutines) to the context fn derives from the tree's stop context: a per-node sub-deadline within the shutdown budget. Its children keep the tree's context.
func (*Node) Child ¶
Child appends a child in startup order. After startup begins, only a currently starting parent may create children. Misuse panics.
func (*Node) Go ¶
Go runs fn on the node's context once the node has started; it is cancelled when the node stops, and the stop waits for it. A non-nil error (or a panic) stops the service. After the node stopped, fn is dropped.
func (*Node) Start ¶
Start starts n's subtree depth-first in creation order. ctx bounds the start hooks; node lifetimes are detached from it. On error the caller must still call Stop, which unwinds whatever started.