Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool dispatches jobs to a fixed set of worker goroutines.
A pool created with a non-positive number of workers is degenerate: it never starts any worker and Do executes the job inline, in the caller goroutine. The same fallback applies after Stop has been called.
func NewWP ¶
func NewWP(nWorkers int) *WorkerPool
func (*WorkerPool) Do ¶
func (wp *WorkerPool) Do(job func())
Do enqueues a job. Once the pool is stopped (or was created without workers), the job runs inline in the calling goroutine.
func (*WorkerPool) Run ¶
func (wp *WorkerPool) Run()
func (*WorkerPool) Stop ¶
func (wp *WorkerPool) Stop()
Stop stops accepting new jobs, waits for already queued and in-flight jobs to finish, and then releases the workers. It is safe to call more than once.
Click to show internal directories.
Click to hide internal directories.