taskpool

package
v0.0.0-...-b94c5f0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2017 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package taskpool provides task pool with variable amount of worker goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task func(input interface{}) (output interface{})

Task is a work function with one input parameter and one output.

type TaskPool

type TaskPool struct {
	Input  chan interface{}
	Output chan interface{}
	// contains filtered or unexported fields
}

TaskPool is task pool with variable amount of worker goroutines. It should be created with New(). There should be only one sender to Input and one receiver from Output. Input must be closed by user before invoking Wait(). Output is closed by Wait().

func New

func New(task Task, size uint) *TaskPool

New creates new TaskPool with given task and initial size.

func (*TaskPool) Resize

func (p *TaskPool) Resize(size uint) bool

Resize changes amount of worker goroutines and returns true if amount was changed.

This method is not thread-safe.

func (*TaskPool) Size

func (p *TaskPool) Size() uint

Size returns current amount of worker goroutines.

This method is not thread-safe.

func (*TaskPool) Wait

func (p *TaskPool) Wait()

Wait waits for worker goroutines to finish and closes Output. User should call this method after closing Input. User should continue to receive from Output until it's closed.

This method is not thread-safe.

Jump to

Keyboard shortcuts

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