Documentation ¶
Overview ¶
Package routinepool lets you create a workerpool made of Go routines.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrShutdown = errors.New("Shutdown in progress")
ErrShutdown is the error returned if the pool shutdown is already in progress And you try calling Stop()
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is the struct which handles the worker pool
Example ¶
var completed uint64 const ( jobs = 32 poolsize = 4 ) p := New(poolsize, jobs) //Start the routine pool and wait for jobs/tasks p.Start() for i := 0; i < jobs; i++ { go p.Push(func() { time.Sleep(time.Millisecond * 50) atomic.AddUint64(&completed, 1) }) } //Gracefully shutdown the routine pool. p.Stop() fmt.Println("Active jobs:", p.Active(), "Pending jobs:", p.Pending(), "Completed:", completed, "out of", jobs)
Output: Active jobs: 0 Pending jobs: 0 Completed: 32 out of 32
Click to show internal directories.
Click to hide internal directories.