ReceiverTask

Struct ReceiverTask 

Source
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 (typically tokio::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>

Source

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.

Source

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:

  1. Stop reading new data from the network
  2. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.