Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GracefulListener ¶
A GracefulListener differs from a standard net.Listener in one way: if Accept() is called after it is gracefully closed, it returns a listenerAlreadyClosed error. The GracefulServer will ignore this error.
func NewListener ¶
func NewListener(l net.Listener, s *GracefulServer) *GracefulListener
func (*GracefulListener) Close ¶
func (l *GracefulListener) Close() error
type GracefulServer ¶
type GracefulServer struct { Shutdown chan bool InnerServer http.Server // contains filtered or unexported fields }
A GracefulServer maintains a WaitGroup that counts how many in-flight requests the server is handling. When it receives a shutdown signal, it stops accepting new requests but does not actually shut down until all in-flight requests terminate.
func NewServer ¶
func NewServer() *GracefulServer
Creates a new GracefulServer. The server will begin shutting down when a value is passed to the Shutdown channel.
func (*GracefulServer) FinishRoutine ¶
func (s *GracefulServer) FinishRoutine()
Decrement the server's WaitGroup. Used this to complement StartRoutine().
func (*GracefulServer) ListenAndServe ¶
func (s *GracefulServer) ListenAndServe(addr string, handler http.Handler) error
A helper function that emulates the functionality of http.ListenAndServe.
func (*GracefulServer) Serve ¶
Similar to http.Serve. The listener passed must wrap a GracefulListener.
func (*GracefulServer) StartRoutine ¶
func (s *GracefulServer) StartRoutine()
Increments the server's WaitGroup. Use this if a web request starts more goroutines and these goroutines are not guaranteed to finish before the request.