queue

package
v0.2.0-rc6 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package queue provides a simple queue implementation with support for deduping equivalent jobs using the notion of a unique key for each job.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key string

Key is a unique key for a job.

func (Key) String

func (k Key) String() string

type Queue

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

Queue implements the queue.

func New

func New(concurrency int) *Queue

New creates a queue with the supplied concurrency.

func (*Queue) Dequeue

func (q *Queue) Dequeue(key Key)

Dequeue removes any waiting job having the supplied key. Running jobs are not affected.

func (*Queue) Enqueue

func (q *Queue) Enqueue(key Key, fn func() error)

Enqueue enqueues a job with a specific key. The job will not be added to the queue if there already exists a job that is waiting to be processed which has the same key. Note that a running job for the same key will still cause this one to be enqueued.

func (*Queue) Start

func (q *Queue) Start(ctx context.Context)

Start starts the background processing for the queue. Processing stops when the context is canceled.

func (*Queue) WaitForKey

func (q *Queue) WaitForKey(key Key)

WaitForKey waits until the running and waiting jobs for this key have completed. Note that it will not wait forever even the queue keeps getting new job with the same key after this function is called.

Jump to

Keyboard shortcuts

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