Skip to main content
Queue is a generic first-in, first-out (FIFO) data structure. Elements are removed in the same order they were inserted. The library provides four implementations that share a common interface, each with different allocation strategies so you can choose the best fit for your workload.

Installation

Interface

Constructors

All four constructors accept a sizeHint parameter and return container.Queue[E].
int
required
A non-binding hint for the initial capacity. Some implementations use it to pre-allocate storage; others ignore it. Pass 0 if you have no estimate.

Choosing an implementation

Optional Countable interface

Some implementations also satisfy container.Countable, which adds a Len() method. You should always check for it at runtime via a type assertion rather than relying on a specific implementation.
Len() is not part of the core Queue interface because not all implementations provide it. Always guard the call with a type assertion as shown above.

Example

Queue is not concurrency-safe. Do not share a Queue across goroutines without external synchronization. For concurrent producer-consumer scenarios, use WaitableQueue instead.