pub struct PriorityReceiver<T> { /* private fields */ }Expand description
Priority receiver that processes messages by priority
Combines multiple receivers and delivers messages in priority order. Messages with higher priority are processed before lower priority ones.
Implementations§
Source§impl<T> PriorityReceiver<T>where
T: Send + 'static,
impl<T> PriorityReceiver<T>where
T: Send + 'static,
Sourcepub fn with_config(config: PriorityQueueConfig) -> Self
pub fn with_config(config: PriorityQueueConfig) -> Self
Create a new priority receiver with custom configuration
Sourcepub fn add_source(&mut self, receiver: Receiver<T>, priority: Priority)
pub fn add_source(&mut self, receiver: Receiver<T>, priority: Priority)
Add a message source with the specified priority
§Example
let mut prio_rx = PriorityReceiver::new();
let emergency = ctx.subscribe("/safety/emergency").await?;
prio_rx.add_source(emergency, Priority::Critical);
let telemetry = ctx.subscribe("/sensor/telemetry").await?;
prio_rx.add_source(telemetry, Priority::Low);Sourcepub async fn recv(&mut self) -> Option<(T, Priority)>
pub async fn recv(&mut self) -> Option<(T, Priority)>
Receive the next message in priority order
Returns None when all sources are closed.
Returns Some((message, priority)) with the highest priority message available.
§Starvation Prevention
If configured, this method will occasionally process lower-priority messages even when higher-priority messages are available, to prevent starvation.
Sourcepub fn stats(&self) -> PriorityQueueStats
pub fn stats(&self) -> PriorityQueueStats
Get statistics about the priority queue
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for PriorityReceiver<T>
impl<T> RefUnwindSafe for PriorityReceiver<T>where
T: RefUnwindSafe,
impl<T> Send for PriorityReceiver<T>where
T: Send,
impl<T> Sync for PriorityReceiver<T>
impl<T> Unpin for PriorityReceiver<T>where
T: Unpin,
impl<T> UnwindSafe for PriorityReceiver<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more