worker-pools: Index | Files

package pool

import ""


Package Files

worker_pool.go worker_pool_manager.go

type BaseWorkerPool Uses

type BaseWorkerPool struct {
    // contains filtered or unexported fields

BaseWorkerPool is the base implementation of WorkerPool

func (*BaseWorkerPool) Dispose Uses

func (p *BaseWorkerPool) Dispose()

Dispose the pool, closing down the workers and releasing any shared resources.

func (*BaseWorkerPool) Submit Uses

func (p *BaseWorkerPool) Submit(w Work)

Submit an item of Work to be executed.

type Factory Uses

type Factory func(maxSize int) (WorkerPool, error)

Factory builds a new WorkerPool

type Work Uses

type Work func()

Work - a unit of work

type WorkerPool Uses

type WorkerPool interface {
    Submit(w Work)
    // contains filtered or unexported methods

WorkerPool is a fixed-size pool of workers.

func NewWorkerPool Uses

func NewWorkerPool(maxSize int) (WorkerPool, error)

NewWorkerPool builds a new BaseWorkerPool and return it as a WorkerPool. This is the default pool factory.

type WorkerPoolManager Uses

type WorkerPoolManager struct {
    // contains filtered or unexported fields

WorkerPoolManager - Self-expiring, lazily constructed map of fixed-size worker pools safe for concurrent use

func NewWorkerPoolManager Uses

func NewWorkerPoolManager(
    poolSize int, stalePoolExpiration time.Duration, maxPoolLifetime time.Duration,
) *WorkerPoolManager

NewWorkerPoolManager factory constructor

* poolSize - The max number of workers for each key * stalePoolExpiration - how long to cache unused pools for * maxPoolLifetime - max time to allow pools to live

func (*WorkerPoolManager) GetPool Uses

func (m *WorkerPoolManager) GetPool(key string, sendSize int) (WorkerPool, chan<- bool)

GetPool returns the WorkerPool for this key, building a BaseWorkerPool and caching it if necessary. Spawns sendSize workers, up to a max of the manager's poolSize.

This returns the pool in an "unexpirable" state - the caller should signal the returned done channel when it no longer requires the returned bundle.

func (*WorkerPoolManager) GetPoolWithFactory Uses

func (m *WorkerPoolManager) GetPoolWithFactory(
    key string, sendSize int, factory Factory,
) (WorkerPool, chan<- bool, error)

GetPoolWithFactory returns the WorkerPool for this key, allowing you to specify a custom pool.Factory if you want to build a custom WorkerPool implementation which embeds a BaseWorkerPool and attaches supplimentary shared data for the pool.

Package pool imports 3 packages (graph). Updated 2018-08-01. Refresh now. Tools for package owners.