Documentation ¶
Index ¶
- Variables
- type GoroutineExtendedWorker
- type GoroutineInterruptable
- type GoroutineWorker
- type WorkPool
- func (pool *WorkPool) Close() error
- func (pool *WorkPool) NumPendingAsyncJobs() int32
- func (pool *WorkPool) NumWorkers() int
- func (pool *WorkPool) Open() (*WorkPool, error)
- func (pool *WorkPool) PublishExpvarMetrics(poolName string)
- func (pool *WorkPool) SendWork(jobData interface{}) (interface{}, error)
- func (pool *WorkPool) SendWorkAsync(jobData interface{}, after func(interface{}, error))
- func (pool *WorkPool) SendWorkTimed(milliTimeout time.Duration, jobData interface{}) (interface{}, error)
- func (pool *WorkPool) SendWorkTimedAsync(milliTimeout time.Duration, jobData interface{}, ...)
Constants ¶
This section is empty.
Variables ¶
var ( ErrPoolAlreadyRunning = errors.New("the pool is already running") ErrPoolNotRunning = errors.New("the pool is not running") ErrJobNotFunc = errors.New("generic worker not given a func()") ErrWorkerClosed = errors.New("worker was closed") ErrJobTimedOut = errors.New("job request timed out") )
Functions ¶
This section is empty.
Types ¶
type GoroutineExtendedWorker ¶
type GoroutineExtendedWorker interface { // Called when the pool is opened, this will be called before any jobs are sent. Initialize() // Called when the pool is closed, this will be called after all jobs are completed. Terminate() }
GoroutineExtendedWorker - An optional interface that can be implemented if the worker needs more control over its state.
type GoroutineInterruptable ¶
type GoroutineInterruptable interface {
// Called when the current job has been abandoned by the client.
Interrupt()
}
GoroutineInterruptable - An optional interface that can be implemented in order to allow the worker to drop jobs when they are abandoned.
type GoroutineWorker ¶
type GoroutineWorker interface { // Called for each job, expects the result to be returned synchronously Job(interface{}) interface{} // Called after each job, this indicates whether the worker is ready for the next job. // The default implementation is to return true always. If false is returned then the // method is called every five milliseconds until either true is returned or the pool // is closed. Ready() bool }
type WorkPool ¶
type WorkPool struct {
// contains filtered or unexported fields
}
WorkPool contains the structures and methods required to communicate with your pool, it must be opened before sending work and closed when all jobs are completed.
You may open and close a pool as many times as you wish, calling close is a blocking call that guarantees all goroutines are stopped.
func CreateCustomPool ¶
func CreateCustomPool(customWorkers []GoroutineWorker) *WorkPool
CreateCustomPool - Creates a pool for an array of custom workers. The custom workers must implement TunnyWorker, and may also optionally implement TunnyExtendedWorker and TunnyInterruptable.
func CreatePool ¶
CreatePool - Creates a pool of workers, and takes a closure argument which is the action to perform for each job.
func CreatePoolGeneric ¶
CreatePoolGeneric - Creates a pool of generic workers. When sending work to a pool of generic workers you send a closure (func()) which is the job to perform.
func (*WorkPool) NumPendingAsyncJobs ¶
NumPendingAsyncJobs - Get the current count of async jobs either in flight, or waiting for a worker
func (*WorkPool) NumWorkers ¶
NumWorkers - Number of workers in the pool
func (*WorkPool) PublishExpvarMetrics ¶
PublishExpvarMetrics - Publishes the NumWorkers and NumPendingAsyncJobs to expvars
func (*WorkPool) SendWork ¶
SendWork - Send a job to a worker and return the result, this is a synchronous call.
func (*WorkPool) SendWorkAsync ¶
SendWorkAsync - Send a job to a worker without blocking, and optionally send the result to a receiving closure. You may set the closure to nil if no further actions are required.
func (*WorkPool) SendWorkTimed ¶
func (pool *WorkPool) SendWorkTimed(milliTimeout time.Duration, jobData interface{}) (interface{}, error)
SendWorkTimed - Send a job to a worker and return the result, this is a synchronous call with a timeout.
func (*WorkPool) SendWorkTimedAsync ¶
func (pool *WorkPool) SendWorkTimedAsync( milliTimeout time.Duration, jobData interface{}, after func(interface{}, error), )
SendWorkTimedAsync - Send a timed job to a worker without blocking, and optionally send the result to a receiving closure. You may set the closure to nil if no further actions are required.