Queue module provides asynchronous, concurrent queues for message passing between producers and consumers with built-in backpressure support.
Overview
AQueue<A, E> is an asynchronous queue that:
- Can be offered to (enqueue) and taken from (dequeue)
- Supports concurrent producers and consumers
- Provides backpressure strategies (suspend, drop, slide)
- Can signal completion or failure
- Handles concurrent access safely
Creating Queues
Bounded Queue
Creates a queue with backpressure when full:Unbounded Queue
Creates a queue without capacity limits:Dropping Queue
Drops new items when full:Sliding Queue
Removes oldest items when full:Offering Items
Offer Single Item
Offer Multiple Items
Taking Items
Take Single Item
Take Multiple Items
Take All Available
Producer-Consumer Pattern
Multiple Consumers
Queue State and Inspection
Check Size and Capacity
Completion and Errors
Signal Completion
Signal Failure
Queue as a Service
Integration with Streams
Advanced Patterns
Priority Queue Simulation
Rate Limiting
Best Practices
- Choose the right queue type: Use bounded for backpressure, unbounded for fire-and-forget
- Signal completion: Use Queue.done() to gracefully shutdown consumers
- Handle errors properly: Use Queue.fail() to propagate errors to consumers
- Avoid blocking: Process items asynchronously to prevent blocking
- Use appropriate capacity: Size queues based on producer/consumer rates
- Monitor queue depth: Track queue size to detect bottlenecks