workers

package module
Version: v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 2 Imported by: 0

README

go-workers

go get github.com/Zytekaron/go-workers

Support: Contact Me

Method Overview

Creation

NewPool(size int, run RunFunc) Create a new WorkerPool with an initial worker count
NewBufferedPool(size int, bufSize int, run RunFunc) Create a new WorkerPool with an initial worker count and job buffer size

RunFunc = func(interface{})

Basic usage

Pool#Size() Get the total number of workers in this WorkerPool
Pool#Busy() Get the number of busy workers in this WorkerPool
Pool#Run(data interface{}) Add a job to this WorkerPool

Scaling

Pool#ScaleUp(newSize int) Scale the WorkerPool up to a new specified size
Pool#ScaleUp(newSize int) Scale the WorkerPool down to a new specified size

Examples

Example usage can be found here

License

go-workers is licensed under the MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RunFunc

type RunFunc func(...interface{})

type WorkerPool

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

func NewBufferedPool

func NewBufferedPool(size, bufSize int, run RunFunc) *WorkerPool

Create a new WorkerPool with an initial worker count and job buffer size

The job buffer allows new jobs to be queued without blocking if all the workers are busy

Panics when size < 0

func NewPool

func NewPool(size int, run RunFunc) *WorkerPool

Create a new WorkerPool with an initial worker count

Panics when size < 0

func (*WorkerPool) Busy

func (w *WorkerPool) Busy() int

Get the number of busy workers in this WorkerPool

func (*WorkerPool) Excess added in v1.0.2

func (w *WorkerPool) Excess() int

Get the number of workers waiting to close in this WorkerPool

func (*WorkerPool) Run

func (w *WorkerPool) Run(data ...interface{})

Add a job to this WorkerPool

func (*WorkerPool) ScaleDown

func (w *WorkerPool) ScaleDown(newSize int) error

Scale the WorkerPool down to a new specified size

Blocks until all workers have been stopped. Safe to run in the background.

func (*WorkerPool) ScaleTo added in v1.0.2

func (w *WorkerPool) ScaleTo(newSize int) error

Resize the WorkerPool by scaling up or down to accommodate a new size

func (*WorkerPool) ScaleUp

func (w *WorkerPool) ScaleUp(newSize int) error

Scale the WorkerPool up to a new specified size

Safe to run in the background.

func (*WorkerPool) Size

func (w *WorkerPool) Size() int

Get the total number of workers in this WorkerPool

func (*WorkerPool) Stop

func (w *WorkerPool) Stop()

Stop the WorkerPool by closing all channels and stopping all workers

func (*WorkerPool) StopAndCount added in v1.0.2

func (w *WorkerPool) StopAndCount()

Stop the WorkerPool and keep track of the channels waiting to close by sending a closing signal to each worker. Slower than Stop()

Blocks until all workers that were running have been closed. Workers stopped due to down-scaling do not cause this function to block.

func (*WorkerPool) Waiting added in v1.0.2

func (w *WorkerPool) Waiting() int

Get the number of workers currently waiting for jobs

Equivalent to Size() - Busy()

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL