pool: github.com/stefantalpalaru/pool Index | Files | Directories

package pool

import "github.com/stefantalpalaru/pool"

Package pool provides a worker pool.


Package Files


type Job Uses

type Job struct {
    F      func(...interface{}) interface{}
    Args   []interface{}
    Result interface{}
    Err    error
    // contains filtered or unexported fields

Job holds all the data related to a worker's instance.

type Pool Uses

type Pool struct {
    // contains filtered or unexported fields

Pool is the main data structure.

func New Uses

func New(workers int) (pool *Pool)

New creates a new Pool.

func (*Pool) Add Uses

func (pool *Pool) Add(f func(...interface{}) interface{}, args ...interface{})

Add creates a Job from the given function and args and adds it to the Pool.

func (*Pool) Results Uses

func (pool *Pool) Results() (res []*Job)

Results retrieves the completed jobs.

func (*Pool) Run Uses

func (pool *Pool) Run()

Run starts the Pool by launching the workers. It's OK to start an empty Pool. The jobs will be fed to the workers as soon as they become available.

func (*Pool) Status Uses

func (pool *Pool) Status() stats

Status returns a "stats" instance.

func (*Pool) Stop Uses

func (pool *Pool) Stop()

Stop will signal the workers to exit and wait for them to actually do that. It also releases any other resources (e.g.: it stops the supervisor goroutine) so call this method when you're done with the Pool instance to allow the GC to do its job.

func (*Pool) Wait Uses

func (pool *Pool) Wait()

Wait blocks until all the jobs in the Pool are done.

func (*Pool) WaitForJob Uses

func (pool *Pool) WaitForJob() *Job

WaitForJob blocks until a completed job is available and returns it. If there are no jobs running, it returns nil.


examplesExercise: Web Crawler - http://tour.golang.org/#70 modified to use the worker pool

Package pool imports 5 packages (graph) and is imported by 4 packages. Updated 2016-07-14. Refresh now. Tools for package owners.