workerpool

package
v0.2103.8 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package workerpool implements a simple goroutine-based workerpool with a configurable number of workers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool is a pool of goroutine workers.

Notes:

  • The pool is always constructed with one active worker goroutine.
  • Once closed, it can not be used anymore.

func New

func New(name string) *Pool

New creates and returns a new worker pool with one worker goroutine.

func (*Pool) Quit

func (p *Pool) Quit() <-chan struct{}

Quit returns a channel that will be closed when the pool stops.

func (*Pool) Resize

func (p *Pool) Resize(newCount uint)

Resize sets the number of parallel goroutine workers to the number given.

newCount must be greater than 0.

func (*Pool) Stop

func (p *Pool) Stop()

Stop causes all worker goroutines to shut down.

The pool must not be used for any further tasks after calling this method.

func (*Pool) Submit

func (p *Pool) Submit(job func()) <-chan struct{}

Submit adds a task to the pool's queue and returns a channel that will be closed once the task is complete.

Jump to

Keyboard shortcuts

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