Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStopped = errors.New("priorityqueue: stopped")
ErrStopped is returned for outstanding items when the queue is stopped
Functions ¶
This section is empty.
Types ¶
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