Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned when attempting to operate on a closed queue ErrClosed = errors.New("pipe.q.closed") // ErrQueueFull is returned when attempting to push to a full queue ErrQueueFull = errors.New("pipe.q.full") )
Functions ¶
This section is empty.
Types ¶
type Q ¶
type Q[T any] struct { // contains filtered or unexported fields }
Q represents a thread-safe queue with dynamic capacity using linked list It provides the same interface as SliceQueue but uses container/list for storage
func NewQ ¶
NewQ creates a new list-based queue with specified capacity If capacity is 0, the queue has unlimited capacity
func (*Q[T]) Cap ¶ added in v1.2.11
Cap returns the maximum capacity of the queue (0 means unlimited)
func (*Q[T]) Close ¶
func (q *Q[T]) Close()
Close closes the queue, all subsequent operations will return ErrClosed
func (*Q[T]) IsFull ¶ added in v1.2.11
IsFull returns true if the queue is at capacity (always false for unlimited capacity)
func (*Q[T]) Pop ¶
Pop removes and returns an item from the front of the queue Blocks if queue is empty until an item is available or queue is closed
type Queue ¶ added in v1.2.11
type Queue[T any] interface { // Push adds an item to the queue Push(item T) error // Pop removes and returns an item from the queue // Blocks if queue is empty until an item is available or queue is closed Pop() (T, error) // Close closes the queue Close() // Len returns the current number of items in the queue Len() int // Cap returns the maximum capacity of the queue Cap() int // IsClosed returns true if the queue is closed IsClosed() bool // IsFull returns true if the queue is at capacity IsFull() bool // IsEmpty returns true if the queue has no items IsEmpty() bool // Reset clears all items from the queue Reset() }
Queue defines the common interface for all queue implementations
type RingQ ¶ added in v1.2.11
type RingQ[T any] struct { // contains filtered or unexported fields }
RingQ represents a thread-safe ring buffer queue with fixed capacity using pre-allocated slice The slice is allocated at creation time with the specified capacity
func NewRingQ ¶ added in v1.2.11
NewRingQ creates a new slice-based ring queue with fixed capacity The slice is pre-allocated with the specified capacity
func (*RingQ[T]) Close ¶ added in v1.2.11
func (q *RingQ[T]) Close()
Close closes the queue, all subsequent operations will return ErrClosed
func (*RingQ[T]) Pop ¶ added in v1.2.11
Pop removes and returns an item from the front of the queue Blocks if queue is empty until an item is available or queue is closed