priorityworker

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStopped = errors.New("priorityqueue: stopped")

ErrStopped is returned for outstanding items when the queue is stopped

Functions

This section is empty.

Types

type Handler

type Handler[V any] func(context.Context, V) error

Handler is a callback called by PriorityWorker to process an item

type PriorityWorker

type PriorityWorker[V any] struct {
	// contains filtered or unexported fields
}

PriorityWorker implements a concurrency-safe worker that prioritizes work using a priority queue.

func New

func New[V any](handler Handler[V]) *PriorityWorker[V]

New creates a new PriorityWorker that calls the provided handler for every item submitted using Process. It starts a goroutine for the worker's event loop. You must call Stop on the worker when you're done using it.

func (*PriorityWorker[V]) Pause added in v0.11.0

func (pw *PriorityWorker[V]) Pause()

Pause keeps the queue open for new jobs, but won't process them until Unpause is called. Pause is mainly useful for predictable testing of the priority worker.

func (*PriorityWorker[V]) Process

func (pw *PriorityWorker[V]) Process(ctx context.Context, priority int, val V) error

Process enqueues a work item and returns when the item has been dequeued and processed. It returns early if ctx is cancelled or the worker is stopped.

func (*PriorityWorker[V]) Stop

func (pw *PriorityWorker[V]) Stop()

Stop cancels all jobs that haven't started, and returns once the current job has finished

func (*PriorityWorker[V]) Unpause added in v0.11.0

func (pw *PriorityWorker[V]) Unpause()

Unpause reverses Pause

Jump to

Keyboard shortcuts

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