graceful

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package graceful orchestrates shutdown gracefully.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrTimeout

type ErrTimeout []string

ErrTimeout describes tasks that failed to finish in time.

func (ErrTimeout) Error

func (e ErrTimeout) Error() string

Error returns an error message.

type Switch

type Switch struct {
	// contains filtered or unexported fields
}

Switch is graceful shutdown handler.

Please use NewSwitch to create an instance.

func NewSwitch

func NewSwitch(timeout time.Duration, signals ...os.Signal) *Switch

NewSwitch creates shutdown handler that triggers on any of provided OS signals and allows registered tasks to take up to provided timeout.

When switch is triggered, tasks are invoked concurrently.

func (*Switch) OnShutdown

func (s *Switch) OnShutdown(name string, fn func())

OnShutdown adds a named task to run on shutdown.

func (*Switch) Shutdown

func (s *Switch) Shutdown()

Shutdown triggers the switch and stops listening to OS signals.

func (*Switch) Wait

func (s *Switch) Wait() <-chan error

Wait returns a channel that blocks until switch is triggered.

Resulting channel may return a non-empty error if tasks fail to finish within a timeout.

Jump to

Keyboard shortcuts

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