pub struct ReceiverBuilder<R>{ /* private fields */ }Expand description
Builder for configuring and creating a Receiver and ReceiverTask.
This builder allows you to customize the reception pipeline parameters before spawning the background task that handles network I/O and message reassembly.
§Parameters
- capacity: Maximum number of messages that can be buffered per priority level (default: 16)
- max_frag_size: Maximum size of a message fragment in bytes (default: 1GiB)
Implementations§
Source§impl<R> ReceiverBuilder<R>
impl<R> ReceiverBuilder<R>
Sourcepub fn capacity(self, capacity: usize) -> Self
pub fn capacity(self, capacity: usize) -> Self
Sets the maximum number of messages that can be buffered per priority level.
Default: 16 messages per priority level
Higher values allow for more buffering during traffic bursts but consume more memory. Lower values reduce memory usage but may cause messages to be dropped under congestion.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the timeout for waiting for messages during receive operations.
This timeout determines how long Receiver::recv() will wait for a message to
arrive before returning RecvError::Timeout. The timeout applies to each
individual receive call.
This is the initial timeout value used when the receiver is built. It can be changed
later using Receiver::timeout().
Default: 10 seconds
§Examples
// Configure a 30-second timeout during construction
let (receiver, task) = thubo::receiver(reader).timeout(Duration::from_secs(30)).build();Sourcepub fn max_frag_size(self, max_frag_size: usize) -> Self
pub fn max_frag_size(self, max_frag_size: usize) -> Self
Sets the maximum size of a message fragment in bytes.
Default: 65536 bytes (64KB)
This should match the max_frag_size configured on the sender side. Messages larger
than this size will be automatically fragmented by the sender and reassembled by the
receiver. Smaller values reduce latency for small messages but increase overhead for
large messages.
Sourcepub fn build(self) -> (Receiver, ReceiverTask<R>)
pub fn build(self) -> (Receiver, ReceiverTask<R>)
Builds and returns a Receiver and ReceiverTask.
This method creates the complete reception pipeline:
- Receiver: Handle for receiving messages in strict priority order
- ReceiverTask: Background task that manages network I/O, defragmentation, and message routing
§Background Task
The returned ReceiverTask runs until:
- The connection is closed (EOF or network error)
- A read timeout occurs
- The task is explicitly stopped via
ReceiverTask::stop()