Crate batched_queue

Source
Expand description

§batched-queue

A high-performance, highly-concurrent batched queue implementation for Rust.

batched-queue provides an efficient way to collect individual items into batches for processing, which can significantly improve throughput in high-volume systems.

§Features

  • Batching: Automatically collects items into batches of a configurable size
  • Thread-safe: Designed for concurrent usage with multiple producers and consumers
  • Backpressure: Optional bounded queue to control memory usage
  • Flexible retrieval: Blocking, non-blocking, and timeout-based batch retrieval
  • Multiple implementations: Synchronous (default) and asynchronous modes via feature flags

§Usage

By default, the crate provides a synchronous implementation:

use batched_queue::{BatchedQueue, BatchedQueueTrait};

// Create a queue with batch size of 10
let queue = BatchedQueue::new(10).expect("Failed to create queue");

// Create a sender that can be shared across threads
let sender = queue.create_sender();

// Push items to the queue (in real usage, this would be in another thread)
for i in 0..25 {
    sender.push(i).expect("Failed to push item");
}

// Flush any remaining items that haven't formed a complete batch
sender.flush().expect("Failed to flush");

// Process batches
while let Some(batch) = queue.try_next_batch().expect("Failed to get batch") {
    println!("Processing batch of {} items", batch.len());
    for item in batch {
        // Process each item
        println!("  Item: {}", item);
    }
}

§Feature Flags

Re-exports§

pub use sync::BatchedQueue;

Modules§

sync
Synchronous implementation of the batched queue.

Structs§

ErrorContext
Contextual information about BatchedQueueError.

Enums§

BatchedQueueError
Error type for a batched queue.

Traits§

BatchedQueueTrait
Defines the common interface for batched queue implementations.