interrupts

package
v0.0.769 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package interrupts exposes helpers for graceful handling of interrupt signals

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context() context.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

func ListenAndServe(server *http.Server, gracePeriod time.Duration)

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

func ListenAndServeTLS(server *http.Server, certFile, keyFile string, gracePeriod time.Duration)

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

func Run(work func(ctx context.Context))

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

func Tick(work func(), interval func() time.Duration)

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

func TickLiteral(work func(), interval time.Duration)

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.

Jump to

Keyboard shortcuts

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