shutdown

package
v1.25.2 Latest Latest
Warning

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

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

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 New

func New() *Coordinator

New creates a new Coordinator.

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.

Jump to

Keyboard shortcuts

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