Expand description
Priority-based event queue with backpressure support
This module provides a priority queue for events that ensures important events (like user input and quit commands) are processed before less critical events (like ticks and resize events). It also implements backpressure to prevent memory exhaustion under high load.
§Priority Levels
Events are automatically assigned priorities:
- High: Quit, Key events, Suspend/Resume, Process execution
- Normal: Mouse events, User messages, Paste events
- Low: Tick, Resize, Focus/Blur events
§Backpressure
When the queue reaches 80% capacity, backpressure is activated. If the queue fills completely, lower priority events are dropped in favor of higher priority ones.
§Example
use hojicha_runtime::priority_queue::PriorityEventQueue;
use hojicha_core::event::Event;
#[derive(Debug, Clone, PartialEq)]
struct TestMsg(u32);
let mut queue: PriorityEventQueue<TestMsg> = PriorityEventQueue::new(1000);
// High priority events are processed first
queue.push(Event::Tick).unwrap(); // Low priority
queue.push(Event::User(TestMsg(42))).unwrap(); // Normal priority
queue.push(Event::Quit).unwrap(); // High priority
assert_eq!(queue.pop(), Some(Event::Quit)); // High first
assert_eq!(queue.pop(), Some(Event::User(TestMsg(42)))); // Then normal
assert_eq!(queue.pop(), Some(Event::Tick)); // Low lastStructs§
- Priority
Event Queue - A priority queue for events with automatic backpressure handling
- Queue
Stats - Queue statistics for monitoring and scaling decisions
Enums§
- Priority
- Priority levels for events in the queue
- Resize
Error - Error type for resize operations