Documentation ¶
Overview ¶
alive helps servers to coordinate graceful or fast stopping
Index ¶
- Constants
- type Alive
- func (self *Alive) Add(delta int)
- func (self *Alive) Done()
- func (self *Alive) IsFinished() bool
- func (self *Alive) IsRunning() bool
- func (self *Alive) IsStopping() bool
- func (self *Alive) Stop()
- func (self *Alive) StopChan() <-chan struct{}
- func (self *Alive) String() string
- func (self *Alive) Wait()
- func (self *Alive) WaitChan() <-chan struct{}
- func (self *Alive) WaitTasks()
Constants ¶
const NotRunning = "Alive.Add(): need state Running. Attempted to run new task after Stop()"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Alive ¶
type Alive struct {
// contains filtered or unexported fields
}
Alive waits for subtasks, coordinate graceful or fast shutdown. Exported for easy/fast direct references in your code. Zero `Alive{}` is not usable ever. You *must* call `NewAlive()`.
func (*Alive) Add ¶
Corresponds to `sync.WaitGroup.Add()` `a.Stop() ; a.Add(_)` will `panic(NotRunning)`
func (*Alive) IsFinished ¶
func (*Alive) IsStopping ¶
func (*Alive) Stop ¶
func (self *Alive) Stop()
Stop puts Alive into Stopping mode, closes `StopChan()` and returns immediately. After all pending tasks `Done()` state changes to Finished and unblocks all `Wait*` calls/channel. Multiple and concurrent calls are allowed and produce same result.
func (*Alive) StopChan ¶
func (self *Alive) StopChan() <-chan struct{}
StopChan is closed when `Stop()` is called.
func (*Alive) Wait ¶
func (self *Alive) Wait()
Wait returns after both `Stop()` is called **and** all pending tasks done. Multiple and concurrent `Wait()`/`<-WaitChan()` are allowed and produce same result.