Documentation
¶
Overview ¶
Package shutdown provides orderly shutdown coordination using context cancellation and cleanup callbacks.
Register Closer instances in initialization order. On Shutdown, they are closed in reverse registration order. Each Closer receives the parent context so it can respect deadlines. Shutdown is idempotent.
Package shutdown provides orderly shutdown coordination using context cancellation and cleanup callbacks.
Stability: stable
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Closer ¶
type Closer interface {
// Close performs cleanup. It should respect context cancellation for
// deadline enforcement.
Close(ctx context.Context) error
}
Closer is implemented by any component that needs cleanup on shutdown.
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator manages orderly shutdown of registered Closer instances.
func (*Coordinator) Register ¶
func (c *Coordinator) Register(cl Closer)
Register adds a Closer to the coordinator. On Shutdown, closers are called in reverse registration order.
func (*Coordinator) Shutdown ¶
func (c *Coordinator) Shutdown(ctx context.Context) []error
Shutdown closes all registered Closer instances in reverse order. It collects and returns all errors. If the context is canceled, remaining closers still receive the canceled context so they can choose to abort quickly. Shutdown is idempotent — subsequent calls return nil immediately.