queue

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package queue provides a minimal in-memory bounded queue for keyed work with dedup: jobs are identified by a key, and enqueueing a key that is already active or pending returns its position instead of re-enqueueing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue runs jobs with a configurable concurrency limit. Queue state is in-memory; callers persist their own job metadata and recover on startup.

func New

func New(maxConcurrent int) *Queue

New creates a Queue with the given concurrency limit (minimum 1).

func (*Queue) Enqueue

func (q *Queue) Enqueue(key string, startFn func(), done func()) int

Enqueue adds a job keyed by key. Returns the queue position: 0 if it started immediately, >0 if queued behind other jobs. If the key is already active or pending, Enqueue dedups and returns its current position without re-enqueueing. A completion hook may be provided; when non-nil it runs after the key leaves the active set (so a caller's bookkeeping for the key is torn down only once the queue is done with it), but only when this call actually started the job — a dedup'd enqueue does not run it.

func (*Queue) EnqueueSuccessor

func (q *Queue) EnqueueSuccessor(key string, startFn func(), done func()) int

EnqueueSuccessor queues a new job behind an active job with the same key. If a successor is already pending, it is replaced by the new job. This is useful when the caller has replaced the persisted work for a key while the previous job is finishing.

func (*Queue) GetPosition

func (q *Queue) GetPosition(key string) *int

GetPosition returns nil if the key is unknown or active without a successor, otherwise its 1-based position in the pending queue.

func (*Queue) QueueLength

func (q *Queue) QueueLength() int

QueueLength returns the number of tracked jobs (active + pending).

Jump to

Keyboard shortcuts

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