Documentation ¶
Overview ¶
Package interrupts exposes helpers for graceful handling of interrupt signals
Index ¶
- func Context() context.Context
- func ListenAndServe(server *http.Server, gracePeriod time.Duration)
- func ListenAndServeTLS(server *http.Server, certFile, keyFile string, gracePeriod time.Duration)
- func Run(work func(ctx context.Context))
- func Tick(work func(), interval func() time.Duration)
- func TickLiteral(work func(), interval time.Duration)
- func WaitForGracefulShutdown()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context returns a context that stays is cancelled when an interrupt hits. Using this context is a weak guarantee that your work will finish before process exit as callers cannot signal that they are finished. Prefer to use Run().
func ListenAndServe ¶
ListenAndServe runs the HTTP server and handles shutting it down gracefully on interrupts. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all servers have had time to shut down.
func ListenAndServeTLS ¶
ListenAndServeTLS runs the HTTP server and handles shutting it down gracefully on interrupts. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all servers have had time to shut down.
func Run ¶
Run will do work until an interrupt is received, then signal the worker. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all workers have had time to shut down. This is preferable to getting the raw Context as we can ensure that the work is finished before releasing our share of the wait group on shutdown.
func Tick ¶
Tick will do work on a dynamically determined interval until an interrupt is received. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all workers have had time to shut down.
func TickLiteral ¶
TickLiteral runs Tick with an unchanging interval.
func WaitForGracefulShutdown ¶
func WaitForGracefulShutdown()
WaitForGracefulShutdown waits until all registered servers and workers have had time to gracefully shut down, or times out. This function is blocking.
Types ¶
This section is empty.