valve

package module
v0.0.0-...-9e45288 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2017 License: MIT Imports: 5 Imported by: 81

README

Valve

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValveCtxKey     = &contextKey{"Valve"}
	ErrTimedout     = errors.New("valve: shutdown timed out")
	ErrShuttingdown = errors.New("valve: shutdown in progress")
	ErrOff          = errors.New("valve: valve already shutdown")
)

Functions

This section is empty.

Types

type LeverControl

type LeverControl interface {
	Stop() <-chan struct{}
	Add(delta int) error
	Done()
	Open() error
	Close()
}

func Lever

func Lever(ctx context.Context) LeverControl

Lever returns the lever controls from a context object.

type Valve

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

func New

func New() *Valve

func (*Valve) Add

func (v *Valve) Add(delta int) error

Add increments by `delta` (should be 1), to a waitgroup on the valve that signifies that a block of code must complete before we exit the system.

func (*Valve) Close

func (v *Valve) Close()

Close is an alias for Done() intended to read better for closing a valve.

func (*Valve) Context

func (v *Valve) Context() context.Context

Context returns a fresh context with the Lever value set.

It is useful as the base context in a server, that provides shutdown signaling across a context tree.

func (*Valve) Done

func (v *Valve) Done()

Done decrements the valve waitgroup that informs the lever control that the non-preemptive app code is finished.

func (*Valve) Open

func (v *Valve) Open() error

Open is an alias for Add(1) intended to read better for opening a valve.

func (*Valve) Shutdown

func (v *Valve) Shutdown(timeout time.Duration) error

Shutdown will signal to the context to stop all processing, and will give a grace period of `timeout` duration. If `timeout` is 0 then it will wait indefinitely until all valves are closed.

func (*Valve) ShutdownHandler

func (v *Valve) ShutdownHandler(next http.Handler) http.Handler

ShutdownHandler is an optional HTTP middleware handler that will stop accepting new connections if the server is in a shutting-down state.

If you're using something that github.com/tylerb/graceful which stops accepting new connections on the socket anyways, then this handler wouldnt be necessary, but it is handy otherwise.

func (*Valve) Stop

func (v *Valve) Stop() <-chan struct{}

Stop returns a channel that will be closed once the system is supposed to be stopped. It mimics the behaviou of the ctx.Done() method in "context".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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