Documentation
¶
Overview ¶
Package pooler implements a worker-pool paradigm, relying on channels for all goroutine interoperation in order to achieve high speed an thread-safety. The only other dependency is the sync/atomic package, but it's kept down to a minimum, because we want pooler's operation to be as non-blocking as possible.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackFunc ¶
CallbackFunc is the prototype of a function that will be called by the pool to notify events
type Event ¶
type Event int
Event is an enumerable that represents task-related events
const ( // WorkerCreated is when a "worker" goroutine is created WorkerCreated Event = iota // WorkerShutdown is called when a "worker" goroutine is shut down WorkerShutdown Event = iota // TaskQueued is when the task is first accepted and inserted in the queue TaskQueued Event = iota // TaskStarted is when the job is about to be start executing a task TaskStarted Event = iota // TaskDone is when a task is done running TaskDone Event = iota // TaskDoneWithError is when a job has finished running but returned an error TaskDoneWithError Event = iota // TaskCrashed is when a job is interrupted by an unexpected panic TaskCrashed Event = iota // QueueError is when an attempt to enqueue a task is made while pool is shutting down (panic is caught and gracefully handled) QueueError Event = iota )
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a container for a pool of goroutines that will run the queued tasks
func New ¶
New creates a new Pool object without a Callback function routineNum: maximum number of "worker" goroutines that are allowed to run concurrently maxTasks: maximum number of tasks that can be waiting in line to be executed by the next available goroutine
func NewWithCallback ¶
func NewWithCallback(routineNum int, maxTasks int, cbFunc CallbackFunc) (pool *Pool)
NewWithCallback creates a new Pool object with a Callback function routineNum: maximum number of "worker" goroutines that are allowed to run concurrently maxTasks: maximum number of tasks that can be waiting in line to be executed by the next available goroutine cfFunc: a callback function that will be called when certain events occur (see its prototype in types.go)
func (*Pool) ActiveWorkers ¶
ActiveWorkers returns the number of goroutines that are actually busy doing something
func (*Pool) Enqueue ¶
Enqueue adds a task to the queue of tasks waiting to be executed task: any object that implements the Runnable interface (see types.go)
func (*Pool) IsShuttingDown ¶
IsShuttingDown returns false during normal operation and true if the pool is shutting down; all tasks should periodically check it inside of their "Run" func.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
with_callback
command
|
|
|
with_callback_and_customdata
command
|