queue

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package queue provides a sequential, non-blocking, unbounded task execution queue. It mimics Node.js's event loop and is deeply inspired by Kubernetes workqueue.

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 serializes function execution through a single goroutine. It uses an unbounded slice backed by a condition variable to ensure Enqueue never blocks the caller.

func New

func New() *Queue

New creates a new Queue and starts the internal consumer goroutine.

func (*Queue) Close

func (q *Queue) Close()

Close shuts down the Queue gracefully. It waits for all previously enqueued tasks to complete before returning.

func (*Queue) Enqueue

func (q *Queue) Enqueue(task func())

Enqueue adds a task to the queue for sequential execution. It returns nil on success, or ErrQueueFull if a max size is set and the queue is at capacity. It returns immediately and NEVER blocks.

func (*Queue) Size

func (q *Queue) Size() int

Size returns the number of pending tasks in the queue.

func (*Queue) TryClose

func (q *Queue) TryClose()

TryClose shuts down the Queue without waiting for completion.

Jump to

Keyboard shortcuts

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