pub struct WaitQueue { /* private fields */ }Expand description
Priority-ordered wait queue for resource locks
Implementations§
Source§impl WaitQueue
impl WaitQueue
Sourcepub fn with_max_history(max_history_entries: usize) -> Arc<Self>
pub fn with_max_history(max_history_entries: usize) -> Arc<Self>
Create a new wait queue with custom max history entries
Sourcepub fn subscribe(&self) -> Receiver<WaitQueueEvent>
pub fn subscribe(&self) -> Receiver<WaitQueueEvent>
Subscribe to queue events
Sourcepub async fn register(
self: &Arc<Self>,
resource_key: &str,
agent_id: &str,
priority: u8,
auto_acquire: bool,
) -> WaitQueueHandle
pub async fn register( self: &Arc<Self>, resource_key: &str, agent_id: &str, priority: u8, auto_acquire: bool, ) -> WaitQueueHandle
Register interest in a resource
Returns a handle with a receiver that fires when the agent reaches the front of the queue.
Sourcepub async fn cancel(&self, resource_key: &str, agent_id: &str) -> bool
pub async fn cancel(&self, resource_key: &str, agent_id: &str) -> bool
Remove an agent from the queue
Sourcepub async fn notify_released(&self, resource_key: &str) -> Option<String>
pub async fn notify_released(&self, resource_key: &str) -> Option<String>
Notify that a resource was released
Returns the agent_id of the next waiter (if any) who should acquire.
Sourcepub async fn queue_length(&self, resource_key: &str) -> usize
pub async fn queue_length(&self, resource_key: &str) -> usize
Get queue length for a resource
Sourcepub async fn position(
&self,
resource_key: &str,
agent_id: &str,
) -> Option<usize>
pub async fn position( &self, resource_key: &str, agent_id: &str, ) -> Option<usize>
Get position of agent in queue (0 = front)
Sourcepub async fn estimate_wait(&self, resource_key: &str) -> Option<Duration>
pub async fn estimate_wait(&self, resource_key: &str) -> Option<Duration>
Estimate wait time based on historical data
Sourcepub async fn estimate_wait_at_position(
&self,
resource_key: &str,
position: usize,
) -> Option<Duration>
pub async fn estimate_wait_at_position( &self, resource_key: &str, position: usize, ) -> Option<Duration>
Estimate wait time for a specific position
Sourcepub async fn get_queue_status(&self, resource_key: &str) -> Option<QueueStatus>
pub async fn get_queue_status(&self, resource_key: &str) -> Option<QueueStatus>
Get detailed status of a queue
Sourcepub async fn list_queues(&self) -> Vec<String>
pub async fn list_queues(&self) -> Vec<String>
Get all active queues
Sourcepub async fn is_waiting(&self, agent_id: &str) -> bool
pub async fn is_waiting(&self, agent_id: &str) -> bool
Check if an agent is waiting for any resource
Sourcepub async fn waiting_for(&self, agent_id: &str) -> Vec<String>
pub async fn waiting_for(&self, agent_id: &str) -> Vec<String>
Get all resources an agent is waiting for
Sourcepub async fn record_wait_time(&self, resource_key: &str, duration: Duration)
pub async fn record_wait_time(&self, resource_key: &str, duration: Duration)
Record a completed wait time (for external tracking)
Sourcepub async fn peek_next(&self, resource_key: &str) -> Option<WaiterInfo>
pub async fn peek_next(&self, resource_key: &str) -> Option<WaiterInfo>
Get the next waiter without removing them (peek)
Sourcepub async fn should_auto_acquire(
&self,
resource_key: &str,
agent_id: &str,
) -> bool
pub async fn should_auto_acquire( &self, resource_key: &str, agent_id: &str, ) -> bool
Check if agent should auto-acquire (is at front and has auto_acquire set)