Struct multistream_batch::channel::tx_buf_batch::TxBufBatchChannel [−][src]
pub struct TxBufBatchChannel<I: Debug> { /* fields omitted */ }
Expand description
Batches items in internal buffer up to max_size
items or until max_duration
has elapsed
since the first item appended to the batch. Reference to each item is returned for every
received item as soon as they are received.
The current batch can be retried. Iteration will yield not committed items again.
Implementations
pub fn new(
max_size: usize,
max_duration: Duration,
channel_size: usize
) -> (CommandSender<I>, TxBufBatchChannel<I>)
pub fn new(
max_size: usize,
max_duration: Duration,
channel_size: usize
) -> (CommandSender<I>, TxBufBatchChannel<I>)
Creates batch given maximum batch size in the number of items stored (max_size
)
and maximum duration that batch can last (max_duration
) since the first item appended to it.
Parameter channel_size
defines the maximum number of messages that can be buffered between sender and receiver.
This method also returns CommandSender
endpoint that can be used to send Command
s.
Panics if max_size == 0
.
pub fn with_producer_thread(
max_size: usize,
max_duration: Duration,
channel_size: usize,
producer: impl FnOnce(CommandSender<I>) + Send + 'static
) -> TxBufBatchChannel<I> where
I: Send + 'static,
pub fn with_producer_thread(
max_size: usize,
max_duration: Duration,
channel_size: usize,
producer: impl FnOnce(CommandSender<I>) + Send + 'static
) -> TxBufBatchChannel<I> where
I: Send + 'static,
Calls producer
closure with CommandSender
end of the channel in a newly started thread and
returns TxBufBatchChannel
connected to that CommandSender
.
Gets next item reference received by the batch or signal that the batch is now complete and can be retried or committed.
This call will block until batch becomes ready.
When the CommandSender
end has dropped, this method returns with Err(EndOfStreamError)
after all
outstanding items were flushed.
Pops last item returned by next
from internal buffer - it won’t be retried.
Can be called multiple times to consume the internal buffer starting at last next
item
position.
Checks if previous self.next()
call found channel to be disconnected.
Restarts batch making self.next()
to iterate already appended items starting from oldest one in current batch.
Returns number of buffered items that were already visited by the next
call in current batch.
pub fn drain_to_end(self) -> DrainToEnd<I>ⓘNotable traits for DrainToEnd<I>impl<I: Debug> Iterator for DrainToEnd<I> type Item = I;
pub fn drain_to_end(self) -> DrainToEnd<I>ⓘNotable traits for DrainToEnd<I>impl<I: Debug> Iterator for DrainToEnd<I> type Item = I;
impl<I: Debug> Iterator for DrainToEnd<I> type Item = I;
Converts to an iterator that will drain all buffered items first and then all items from the channel.