priorityworker

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 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]) 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()

Jump to

Keyboard shortcuts

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