Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferedPool ¶
type BufferedPool interface {
// Do enqueues a task and blocks the goroutine until it's enqueued.
Do(func())
// TryDo will attempt to enqueue the task, if the buffer is full, it will return false
TryDo(func()) bool
// Wait blocks the goroutine until all tasks are complete.
Wait()
// WaitAndClose closes the worker pool once all tasks are complete, you must not try to enqueue more tasks after calling this.
WaitAndClose()
}
BufferedPool is an interface which implements BufferedPoolImpl, allowing you to mock out the pool for tests.
type BufferedPoolImpl ¶
type BufferedPoolImpl struct {
// Tasks is a buffer of all enqueued tasks to be ran by the workers
Tasks chan func()
// WaitGroup tracks how many running/queued tasks there are, we expose Wait() so you can wait until all tasks are complete.
WaitGroup sync.WaitGroup
// contains filtered or unexported fields
}
BufferedPoolImpl is an implementation that is compatible with Pool
func NewBufferedPool ¶
func NewBufferedPool(workers, maxQueue int) *BufferedPoolImpl
NewBufferedPool creates a new instance of BufferedPoolImpl
func (*BufferedPoolImpl) Close ¶
func (w *BufferedPoolImpl) Close()
Close closes the worker pool, you must not try to enqueue more tasks after calling this.
func (*BufferedPoolImpl) Do ¶
func (w *BufferedPoolImpl) Do(cb func())
Do enqueues a task and blocks the goroutine until it's enqueued.
func (*BufferedPoolImpl) Interface ¶
func (w *BufferedPoolImpl) Interface() BufferedPool
Interface is a convenience method which gives you the same instance as an interface.
func (*BufferedPoolImpl) TryDo ¶
func (w *BufferedPoolImpl) TryDo(cb func()) bool
func (*BufferedPoolImpl) Wait ¶
func (w *BufferedPoolImpl) Wait()
Wait blocks the goroutine until all tasks are complete.
func (*BufferedPoolImpl) WaitAndClose ¶
func (w *BufferedPoolImpl) WaitAndClose()
WaitAndClose closes the worker pool once all tasks are complete, you must not try to enqueue more tasks after calling this.
type UnbufferedPool ¶ added in v0.0.10
type UnbufferedPool interface {
// Do enqueues a task and blocks the goroutine until it's enqueued.
Do(func())
// Wait blocks the goroutine until all tasks are complete.
Wait()
}
UnbufferedPool is an interface which implements BufferedPoolImpl, allowing you to mock out the pool for tests.
type UnbufferedPoolImpl ¶ added in v0.0.10
type UnbufferedPoolImpl struct {
// WaitGroup tracks how many running/queued tasks there are, we expose Wait() so you can wait until all tasks are complete.
WaitGroup sync.WaitGroup
}
UnbufferedPoolImpl is an implementation that is compatible with UnbufferedPool.
The main purpose of this tool is to let you ensure all goroutines have been closed before exiting your app, you can pass an instance of this around everywhere instead.
func NewUnbufferedPool ¶ added in v0.0.10
func NewUnbufferedPool() *UnbufferedPoolImpl
NewUnbufferedPool creates a new instance of BufferedPoolImpl
func (*UnbufferedPoolImpl) Do ¶ added in v0.0.10
func (w *UnbufferedPoolImpl) Do(cb func())
Do increments the wait group and invokes the goroutine, then decrements it.
func (*UnbufferedPoolImpl) Wait ¶ added in v0.0.10
func (w *UnbufferedPoolImpl) Wait()
Wait blocks the goroutine until all tasks are complete.