Module frame_events

Expand description

See frame_events for the system contract and examples. Explicit event visibility boundaries for ordered engine systems. Sends enter a pending buffer; advance publishes it and expires the previous frame. Each buffer holds at most capacity events (total retained count <= 2*capacity).

FrameEvents::read and FrameEvents::iter let multiple listeners borrow the same visible events. Drains instead transfer ownership to one consumer; they never consume pending events and allocate no storage. Independent FrameEventReader cursors additionally distinguish an empty read from unread events lost to advance, drain or clear. Readers do not keep old frames alive or change the two-buffer retention bound.

use ferravex_engine::frame_events::FrameEvents;

let mut events = FrameEvents::new(2);
events.send(String::from("hit")).unwrap();
assert!(events.read().is_empty());
events.advance();
events.send(String::from("next frame")).unwrap();
assert_eq!(events.iter().next().map(String::as_str), Some("hit"));
for event in events.drain() {
    assert_eq!(event, "hit");
}
assert_eq!(events.pending_len(), 1);
events.advance();
assert_eq!(events.read()[0], "next frame");
assert_eq!(events.metrics().expired, 0); // The previous frame was drained.
let interval = events.reset_metrics();
assert_eq!(interval.accepted, 2);
assert_eq!(events.read()[0], "next frame"); // Reset preserves events.

Structs§

FrameEventRead
Borrowed events in send order, accompanied by the status before the read.
FrameEventReader
An independent cursor created by FrameEvents::reader.
FrameEvents
Double-buffered events with explicit publication and pending-buffer backpressure.
FrameEventsMetrics
Frame-event activity since construction or the last metrics reset.
FrameReaderStatus
A cursor’s status before a read or reset acknowledges any loss.

Enums§

FrameReaderError
A cursor was supplied to a buffer other than the one that created it.
FrameReaderPosition
A safe reset destination within a reader’s original buffer.