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 (*Queue) Enqueue ¶
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 ¶
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 ¶
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 ¶
QueueLength returns the number of tracked jobs (active + pending).