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 ¶
- type CallbackFuncQueue
- type CallbackFuncQueueErr
- type CallbackFuncTask
- type CallbackFuncTaskErr
- type CallbackFuncWrk
- type Config
- func (c *Config) OnTaskCrashed(fn CallbackFuncTaskErr) *Config
- func (c *Config) OnTaskDone(fn CallbackFuncTask) *Config
- func (c *Config) OnTaskDoneWithError(fn CallbackFuncTaskErr) *Config
- func (c *Config) OnTaskQueued(fn CallbackFuncQueue) *Config
- func (c *Config) OnTaskQueuingError(fn CallbackFuncQueueErr) *Config
- func (c *Config) OnTaskStarted(fn CallbackFuncTask) *Config
- func (c *Config) OnWorkerCreated(fn CallbackFuncWrk) *Config
- func (c *Config) OnWorkerShutdown(fn CallbackFuncWrk) *Config
- type Pool
- type Runnable
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackFuncQueue ¶ added in v1.0.0
type CallbackFuncQueue func(task *Task)
CallbackFuncQueue is the prototype of a function that will be called by the pool to notify of successful events pertaining the queue (like a task successfully enqueued)
type CallbackFuncQueueErr ¶ added in v1.0.0
CallbackFuncQueueErr is the prototype of a function that will be called by the pool to notify of errors pertaining the queue (queuing errors)
type CallbackFuncTask ¶ added in v1.0.0
CallbackFuncTask is the prototype of a function that will be called by the pool to notify when workers start/stop/enqueue tasks
type CallbackFuncTaskErr ¶ added in v1.0.0
CallbackFuncTaskErr is the prototype of a function that will be called by the pool to notify of errors pertaining tasks (typically runtime errors)
type CallbackFuncWrk ¶ added in v1.0.0
type CallbackFuncWrk func(routine int)
CallbackFuncWrk is the prototype of a function that will be called by the pool to notify when workers are created or shutdown
type Config ¶ added in v1.0.0
type Config struct {
// Routines is the desired number of "worker" goroutines
Routines int
// MaxTasks is the maximum number of tasks that can be in this pool's queue at any given time
MaxTasks int
// WorkerCreatedCB is an optional callback func that will be called every time a "worker" goroutine is created
WorkerCreatedCB CallbackFuncWrk
// WorkerShutdownCB is an optional callback func that will be called every time a "worker" goroutine is shutdown
WorkerShutdownCB CallbackFuncWrk
// TaskQueuedCB is an optional callback func that will be called every time a task is successfully added to the pool's queue
TaskQueuedCB CallbackFuncQueue
// TaskQueuingErrorCB is an optional callback func that will be called every time there's a problem adding a task to the pool's queue
TaskQueuingErrorCB CallbackFuncQueueErr
// TaskStartedCB is an optional callback func that will be called every time a task is picked up by a "worker" routine and its execution begins
TaskStartedCB CallbackFuncTask
// TaskDoneCB is an optional callback func that will be called every time a task is done running without errors
TaskDoneCB CallbackFuncTask
// TaskDoneWithErrorCB is an optional callback func that will be called every time a task is done running but has returned an error
TaskDoneWithErrorCB CallbackFuncTaskErr
// TaskCrashedCB is an optional callback func that will be called every time a `panic` has occurred within the Run() method while a task was running
TaskCrashedCB CallbackFuncTaskErr
}
Config is the global pool configuration struct
func (*Config) OnTaskCrashed ¶ added in v1.0.0
func (c *Config) OnTaskCrashed(fn CallbackFuncTaskErr) *Config
OnTaskCrashed sets the callback function that's called when a "worker" goroutine suddenly crashed (panic) while running a task
func (*Config) OnTaskDone ¶ added in v1.0.0
func (c *Config) OnTaskDone(fn CallbackFuncTask) *Config
OnTaskDone sets the callback function that's called when a "worker" goroutine is done running a task, and no error is returned
func (*Config) OnTaskDoneWithError ¶ added in v1.0.0
func (c *Config) OnTaskDoneWithError(fn CallbackFuncTaskErr) *Config
OnTaskDoneWithError sets the callback function that's called when a "worker" goroutine is done running a task, but an error is returned
func (*Config) OnTaskQueued ¶ added in v1.0.0
func (c *Config) OnTaskQueued(fn CallbackFuncQueue) *Config
OnTaskQueued sets the callback function that's called when a new task is successfully added to the pending queue
func (*Config) OnTaskQueuingError ¶ added in v1.0.0
func (c *Config) OnTaskQueuingError(fn CallbackFuncQueueErr) *Config
OnTaskQueuingError sets the callback function that's called when a "worker" goroutine is done running a task, but an error is returned
func (*Config) OnTaskStarted ¶ added in v1.0.0
func (c *Config) OnTaskStarted(fn CallbackFuncTask) *Config
OnTaskStarted sets the callback function that's called when a "worker" goroutine picks up a task from the queue and starts running it
func (*Config) OnWorkerCreated ¶ added in v1.0.0
func (c *Config) OnWorkerCreated(fn CallbackFuncWrk) *Config
OnWorkerCreated sets the callback function that's called when a new "worker" goroutine is created
func (*Config) OnWorkerShutdown ¶ added in v1.0.0
func (c *Config) OnWorkerShutdown(fn CallbackFuncWrk) *Config
OnWorkerShutdown sets the callback function that's called when a new "worker" goroutine is shutdown
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 any Callback functions routines: 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 NewWithConfig ¶ added in v1.0.0
NewWithConfig creates a new Pool object with a user-provided configuration config: a pointer to a Config object (see 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
|