Module events

Expand description

See events for the system contract and examples. Bounded FIFO engine events. Capacity counts events, not their owned payload bytes. Overflow is explicit; retained events preserve send order. EventQueue::try_send_batch admits a whole batch only when every event fits, preserving queued events and the caller’s batch on capacity rejection.

Iteration and draining allocate no storage and do not clone events. A limited drain lets a consumer leave excess work queued for its next tick:

use ferravex_engine::events::{EventQueue, Overflow};

let mut events = EventQueue::new(2, Overflow::RejectNewest);
events.send(10).unwrap();
events.send(20).unwrap();
assert_eq!(events.send(30), Err(30));
assert!(events.is_full());
assert_eq!(events.metrics().rejected, 1);
assert_eq!(events.drain_up_to(1).sum::<i32>(), 10);
assert_eq!(events.iter().copied().next(), Some(20));
assert_eq!(events.remaining_capacity(), 1);
assert_eq!(events.drain().sum::<i32>(), 20);
let interval = events.reset_metrics();
assert_eq!(interval.high_water_mark, 2);
assert_eq!(events.dropped(), 0);

Structs§

EventBatchError
An entire batch was rejected because it exceeded the available event slots.
EventQueue
A bounded queue with explicit overflow and reusable backing storage.
EventQueueMetrics
Backpressure observed since construction or the last metrics reset.

Enums§

Overflow
The action taken when an individual EventQueue::send encounters a full queue. Atomic batches always reject if they do not fit, regardless of this policy.