Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStopped = errors.New("ThreadGroup already stopped")
ErrStopped is returned by ThreadGroup methods if Stop has already been called.
Functions ¶
This section is empty.
Types ¶
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex provides locking functions, and an ability to detect and remove deadlocks.
func New ¶
New takes a maxLockTime and returns a lock. The lock will never stay locked for more than maxLockTime, instead printing an error and unlocking after maxLockTime has passed.
func (*RWMutex) Lock ¶
Lock will lock the RWMutex. The return value must be used as input when calling RUnlock.
func (*RWMutex) RLock ¶
RLock will read lock the RWMutex. The return value must be used as input when calling RUnlock.
type ThreadGroup ¶ added in v1.0.0
type ThreadGroup struct {
// contains filtered or unexported fields
}
ThreadGroup is a sync.WaitGroup with additional functionality for facilitating clean shutdown. Namely, it provides a StopChan method for notifying callers when shutdown occurrs. Another key difference is that a ThreadGroup is only intended be used once; as such, its Add and Stop methods return errors if Stop has already been called.
During shutdown, it is common to close resources such as net.Listeners. Typically, this would require spawning a goroutine to wait on the ThreadGroup's StopChan and then close the resource. To make this more convenient, ThreadGroup provides an OnStop method. Functions passed to OnStop will be called automatically when Stop is called.
func (*ThreadGroup) Add ¶ added in v1.0.0
func (tg *ThreadGroup) Add() error
Add increments the ThreadGroup counter.
func (*ThreadGroup) Done ¶ added in v1.0.0
func (tg *ThreadGroup) Done()
Done decrements the ThreadGroup counter.
func (*ThreadGroup) IsStopped ¶ added in v1.0.0
func (tg *ThreadGroup) IsStopped() bool
IsStopped returns true if Stop has been called.
func (*ThreadGroup) OnStop ¶ added in v1.0.0
func (tg *ThreadGroup) OnStop(fn func())
OnStop adds a function to the ThreadGroup's stopFns set. Members of the set will be called when Stop is called, in reverse order. If the ThreadGroup is already stopped, the function will be called immediately.
func (*ThreadGroup) Stop ¶ added in v1.0.0
func (tg *ThreadGroup) Stop() error
Stop closes the ThreadGroup's stopChan, closes members of the closer set, and blocks until the counter is zero.
func (*ThreadGroup) StopChan ¶ added in v1.0.0
func (tg *ThreadGroup) StopChan() <-chan struct{}
StopChan provides read-only access to the ThreadGroup's stopChan. Callers should select on StopChan in order to interrupt long-running reads (such as time.After).