pool

package module
v0.0.0-...-64ed3a2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2014 License: MIT Imports: 1 Imported by: 3

README

pool

A simple worker pool for go, with optional throttling

Docs: http://godoc.org/github.com/Bowbaq/pool

Documentation

Overview

Package pool provides a simple worker pool with optional throttling of job processing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

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

A Job is the basic unit of work for the pool.

func NewJob

func NewJob(payload interface{}) Job

NewJob creates a new Job with the given payload.

func (Job) Result

func (j Job) Result() interface{}

Result returns the result of a Job. This is a blocking call.

type Pool

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

A Pool represents a set of background workers sharing a common work queue. Each worker is a goroutine and all workers attempt to receive jobs on a common channel. The pool can optionally be rate-limited to a set number of jobs / second, with configurable bursts.

func NewPool

func NewPool(n uint, do Worker) *Pool

NewPool creates a new pool of n workers that process the queue as fast as possible, without rate limitation.

func NewRateLimitedPool

func NewRateLimitedPool(n, rate, burst uint, do Worker) *Pool

NewRateLimitedPool create a new Pool of n workers processing at most rate jobs / second. If burst > 1, up to burst tokens can accumulate letting the pool temporarily exceed the rate until the saved tokens are all consumed. Tokens accumulate when requests are submitted at a rate slower than the processing rate.

func (*Pool) Shutdown

func (p *Pool) Shutdown()

Shutdown the pool. Currently queued jobs will be processed before terminating. Attempting to call Submit after Shutdown is an error.

func (*Pool) Submit

func (p *Pool) Submit(job Job)

Submit a Job to be processed by the pool.

type Worker

type Worker func(id uint, payload interface{}) interface{}

A Worker processes a Job's payload. Once the worker returns, the result is made available to the Job.

Jump to

Keyboard shortcuts

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