Documentation ¶
Index ¶
- Variables
- type LeverControl
- type Valve
- func (v *Valve) Add(delta int) error
- func (v *Valve) Close()
- func (v *Valve) Context() context.Context
- func (v *Valve) Done()
- func (v *Valve) Open() error
- func (v *Valve) Shutdown(timeout time.Duration) error
- func (v *Valve) ShutdownHandler(next http.Handler) http.Handler
- func (v *Valve) Stop() <-chan struct{}
Constants ¶
This section is empty.
Variables ¶
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 (*Valve) Add ¶
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 ¶
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) Shutdown ¶
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 ¶
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.