Documentation ¶
Index ¶
- type Closer
- type CloserFn
- type Stopper
- func (s *Stopper) AddCloser(c Closer)
- func (s *Stopper) IsStopped() <-chan struct{}
- func (s *Stopper) NumTasks() int
- func (s *Stopper) Quiesce()
- func (s *Stopper) RunAsyncTask(f func()) bool
- func (s *Stopper) RunTask(f func()) bool
- func (s *Stopper) RunWorker(f func())
- func (s *Stopper) RunningTasks() TaskMap
- func (s *Stopper) ShouldDrain() <-chan struct{}
- func (s *Stopper) ShouldStop() <-chan struct{}
- func (s *Stopper) Stop()
- type TaskMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Closer ¶
type Closer interface {
Close()
}
Closer is an interface for objects to attach to the stopper to be closed once the stopper completes.
type Stopper ¶
type Stopper struct {
// contains filtered or unexported fields
}
A Stopper provides a channel-based mechanism to stop an arbitrary array of workers. Each worker is registered with the stopper via the RunWorker() method. The system further allows execution of functions through RunTask() and RunAsyncTask().
Stopping occurs in two phases: the first is the request to stop, which moves the stopper into a draining phase. While draining, calls to RunTask() & RunAsyncTask() don't execute the function passed in and return false. When all outstanding tasks have been completed, the stopper closes its stopper channel, which signals all live workers that it's safe to shut down. When all workers have shutdown, the stopper is complete.
An arbitrary list of objects implementing the Closer interface may be added to the stopper via AddCloser(), to be closed after the stopper has stopped.
func (*Stopper) IsStopped ¶
func (s *Stopper) IsStopped() <-chan struct{}
IsStopped returns a channel which will be closed after Stop() has been invoked to full completion, meaning all workers have completed and all closers have been closed.
func (*Stopper) Quiesce ¶
func (s *Stopper) Quiesce()
Quiesce moves the stopper to state draining and waits until all tasks complete. This is used from Stop() and unittests.
func (*Stopper) RunAsyncTask ¶
RunAsyncTask runs function f in a goroutine. It returns false when the Stopper is draining and the function is not executed.
func (*Stopper) RunTask ¶
RunTask adds one to the count of tasks left to drain in the system. Any worker which is a "first mover" when starting tasks must call this method before starting work on a new task. First movers include goroutines launched to do periodic work and the kv/db.go gateway which accepts external client requests.
Returns false to indicate that the system is currently draining and function f was not called.
func (*Stopper) RunWorker ¶
func (s *Stopper) RunWorker(f func())
RunWorker runs the supplied function as a "worker" to be stopped by the stopper. The function <f> is run in a goroutine.
func (*Stopper) RunningTasks ¶
RunningTasks returns a map containing the count of running tasks keyed by call site.
func (*Stopper) ShouldDrain ¶
func (s *Stopper) ShouldDrain() <-chan struct{}
ShouldDrain returns a channel which will be closed when Stop() has been invoked and outstanding tasks should begin to drain.
func (*Stopper) ShouldStop ¶
func (s *Stopper) ShouldStop() <-chan struct{}
ShouldStop returns a channel which will be closed when Stop() has been invoked and outstanding tasks have drained.