[][src]Struct multistream_batch::channel::tx_buf_batch::TxBufBatchChannel

pub struct TxBufBatchChannel<I: Debug> { /* fields omitted */ }

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

impl<I: Debug> TxBufBatchChannel<I>[src]

pub fn new(
    max_size: usize,
    max_duration: Duration,
    channel_size: usize
) -> (Sender<Command<I>>, TxBufBatchChannel<I>)
[src]

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 Sender endpoint that can be used to send Commands.

Panics if max_size == 0.

pub fn with_producer_thread(
    max_size: usize,
    max_duration: Duration,
    channel_size: usize,
    producer: impl FnOnce(Sender<Command<I>>) + Send + 'static
) -> TxBufBatchChannel<I> where
    I: Send + 'static, 
[src]

Calls producer closure with Sender end of the channel in a newly started thread and returns TxBufBatchChannel connected to that Sender.

pub fn next(&mut self) -> Result<TxBufBatchChannelResult<I>, EndOfStreamError>[src]

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 Sender end has dropped, this method returns with Err(EndOfStreamError) after all outstanding items were flushed.

pub fn pop(&mut self) -> Option<I>[src]

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.

pub fn is_disconnected(&self) -> bool[src]

Checks if previous self.next() call found channel to be disconnected.

pub fn retry(&mut self)[src]

Restarts batch making self.next() to iterate already appended items starting from oldest one in current batch.

pub fn clear(&mut self)[src]

Starts new batch dropping all buffered items.

pub fn drain(&mut self) -> Drain<I>[src]

Starts new batch by draining all buffered items.

pub fn as_slice(&self) -> &[I][src]

Returns slice of internal item buffer.

pub fn len(&self) -> usize[src]

Returns number of buffered items.

pub fn into_vec(self) -> Vec<I>[src]

Converts into internal item buffer.

pub fn drain_to_end(self) -> DrainToEnd<I>[src]

Converts to an iterator that will drain all buffered items first and then all items from the channel.

pub fn split(self) -> (BufBatch<I>, Receiver<Command<I>>)[src]

Splits into BufBatch item buffer and channel Receiver end.

Trait Implementations

impl<I: Debug> Debug for TxBufBatchChannel<I>[src]

Auto Trait Implementations

impl<I> RefUnwindSafe for TxBufBatchChannel<I> where
    I: RefUnwindSafe

impl<I> Send for TxBufBatchChannel<I> where
    I: Send

impl<I> Sync for TxBufBatchChannel<I> where
    I: Send + Sync

impl<I> Unpin for TxBufBatchChannel<I> where
    I: Unpin

impl<I> UnwindSafe for TxBufBatchChannel<I> where
    I: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.