concurrency

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WorkerPool

type WorkerPool[MsgType any] struct {
	// contains filtered or unexported fields
}

WorkerPool represents a proccessor for MsgType objects, using a worker pool to allocate resources.

func NewWorkerPool

func NewWorkerPool[MsgType any](workers int, queueRatio int) *WorkerPool[MsgType]

New returns a new WorkerPool[MsgType] with given number of workers and queue ratio, where the queue ratio is multiplied by no. workers to get queue size. If args < 1 then suitable defaults are determined from the runtime's GOMAXPROCS variable.

func (*WorkerPool[MsgType]) Queue

func (w *WorkerPool[MsgType]) Queue(msg MsgType)

Queue will queue provided message to be processed with there's a free worker.

func (*WorkerPool[MsgType]) SetProcessor

func (w *WorkerPool[MsgType]) SetProcessor(fn func(context.Context, MsgType) error)

SetProcessor will set the Worker's processor function, which is called for each queued message.

func (*WorkerPool[MsgType]) Start

func (w *WorkerPool[MsgType]) Start() error

Start will attempt to start the underlying worker pool, or return error.

func (*WorkerPool[MsgType]) Stop

func (w *WorkerPool[MsgType]) Stop() error

Stop will attempt to stop the underlying worker pool, or return error.

Jump to

Keyboard shortcuts

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