Documentation
¶
Overview ¶
Package closer manages graceful shutdown of resources. Cleanup handlers run in LIFO order (last registered, first closed), matching resource dependency order. It exposes both a process-global default (Add/Close/CloseSync) for the common single-lifecycle application, and an instance API (New/NewWithWait) for callers that need an isolated lifecycle.
It mirrors the lavka-promoaction app/cls design.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultSignals = []os.Signal{ syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP, }
DefaultSignals is the default list of signals NewWithWait listens for.
Functions ¶
Types ¶
type Closer ¶
type Closer struct {
// contains filtered or unexported fields
}
Closer manages graceful shutdown of resources, executing registered cleanup handlers in LIFO (Last-In-First-Out) order.
func NewWithWait ¶
NewWithWait creates a Closer and starts a goroutine that blocks until one of the given signals arrives (DefaultSignals when none are passed). Wait blocks until that happens.
func (*Closer) Add ¶
Add adds a shutdown function. Handlers run in LIFO order on Close/CloseSync. A nil fn is ignored.
func (*Closer) Close ¶
Close executes the handlers asynchronously (concurrently). It does NOT guarantee LIFO order; use CloseSync when order matters.