worker

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2017 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package worker implements a worker pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(ctx context.Context, job Job) (result interface{}, err error)

Func does the actual work within a Pool.

type Job

type Job struct {
	Data   interface{}
	Result interface{}
	Error  error
}

Job is one unit of work. It is given to a Func, and the returned result and error are stored in Result and Error.

type Pool

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

Pool implements a worker pool.

func New

func New(ctx context.Context, n int, f Func, jobChan <-chan Job, resultChan chan<- Job) *Pool

New returns a new worker pool with n goroutines, each running the function f. The workers are started immediately.

func (*Pool) Wait

func (p *Pool) Wait()

Wait waits for all worker goroutines to terminate, afterwards the output channel is closed.

Jump to

Keyboard shortcuts

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