pub struct ReceiverTask<R> { /* private fields */ }Expand description
Background task handle for managing network I/O and message defragmentation.
The ReceiverTask runs in a separate async task and handles:
- Reading batches from the network with timeout protection
- Decoding and routing messages to priority queues
- Automatic defragmentation of large messages split across batches
- Keep-alive message processing
- Graceful shutdown
§Type Parameters
R- The async reader type (typicallytokio::net::tcp::OwnedReadHalf)
§Examples
use std::time::Duration;
// Configure the reader task
receiver_task.set_read_timeout(Duration::from_secs(5));
// Check statistics (requires `stats` feature)
#[cfg(feature = "stats")]
{
let stats = receiver_task.get_stats();
println!("Received {} batches, {} bytes", stats.batches, stats.bytes);
}
// Gracefully stop the task
let reader = receiver_task.stop().await?;
Implementations§
Source§impl<R> ReceiverTask<R>
impl<R> ReceiverTask<R>
Sourcepub fn set_read_timeout(&self, timeout: Duration)
pub fn set_read_timeout(&self, timeout: Duration)
Sets the timeout for network read operations.
If a read operation takes longer than this timeout, it will be aborted and the reader task will terminate. This prevents hanging on slow or unresponsive network connections.
§Default
The default read timeout is 10 seconds.
Sourcepub fn stop(self) -> JoinHandle<R>
pub fn stop(self) -> JoinHandle<R>
Stops the reader task and returns a handle to await its completion.
This method signals the reader task to terminate and returns a
JoinHandle that can be awaited to retrieve the underlying reader.
The reader task will:
- Stop reading new data from the network
- Return the underlying reader
§Returns
A JoinHandle<R> that resolves to the underlying reader when the task
completes.
§Examples
// Stop the reader task and wait for completion
let join_handle = receiver_task.stop();
let reader = join_handle.await?;
println!("Reader task stopped, underlying reader recovered");Auto Trait Implementations§
impl<R> Freeze for ReceiverTask<R>
impl<R> RefUnwindSafe for ReceiverTask<R>
impl<R> Send for ReceiverTask<R>where
R: Send,
impl<R> Sync for ReceiverTask<R>where
R: Send,
impl<R> Unpin for ReceiverTask<R>
impl<R> UnwindSafe for ReceiverTask<R>
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