concurrency

package module
v1.0.1-0...-7c3cdd7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2017 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PoolClosedError = errors.New("pool closed")
	PoolIsFullError = errors.New("pool is full")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Capacity     int
	IdleTimeout  time.Duration
	CloseTimeout time.Duration
}

Config is common for all pools

type Factory

type Factory func() (Resource, error)

type Resource

type Resource interface {
	io.Closer
}

type ResourcePool

type ResourcePool struct {
	// contains filtered or unexported fields
}

func NewResourcePool

func NewResourcePool(ctx context.Context, config Config, factory Factory) (p *ResourcePool)

func (*ResourcePool) Close

func (p *ResourcePool) Close() (err error)

func (*ResourcePool) Get

func (p *ResourcePool) Get(ctx context.Context) (r Resource, err error)

func (*ResourcePool) Open

func (p *ResourcePool) Open() (err error)

func (*ResourcePool) Put

func (p *ResourcePool) Put(r Resource) (err error)

func (*ResourcePool) Wait

func (p *ResourcePool) Wait() (err error)

type Worker

type Worker struct {
	*supervisor.Control
	// contains filtered or unexported fields
}

func (*Worker) Execute

func (w *Worker) Execute(ctx context.Context, fn func())

func (*Worker) Open

func (w *Worker) Open() (err error)

type WorkerPool

type WorkerPool struct {
	// contains filtered or unexported fields
}

WorkerPool uses pool of workers to execute tasks

func NewWorkerPool

func NewWorkerPool(ctx context.Context, config Config) (p *WorkerPool)

func (*WorkerPool) Close

func (p *WorkerPool) Close() (err error)

func (*WorkerPool) Execute

func (p *WorkerPool) Execute(ctx context.Context, fn func()) (err error)

func (*WorkerPool) Get

func (p *WorkerPool) Get(ctx context.Context) (w *Worker, err error)

Take worker from pool

func (*WorkerPool) Open

func (p *WorkerPool) Open() (err error)

func (*WorkerPool) Put

func (p *WorkerPool) Put(w *Worker) (err error)

func (*WorkerPool) Wait

func (p *WorkerPool) Wait() (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL