[−][src]Struct multistream_batch::channel::multi_buf_batch::MultiBufBatchChannel
Collects items into multiple batches based on the stream key.
A batch may become ready after collecting max_size
number of items or until max_duration
has elapsed
since the first item appended to the batch.
Batch item buffers are cached and reused to avoid allocations.
Implementations
impl<K, I> MultiBufBatchChannel<K, I> where
K: Debug + Ord + Hash + Send + Clone + 'static,
I: Debug + Send + 'static,
[src]
K: Debug + Ord + Hash + Send + Clone + 'static,
I: Debug + Send + 'static,
pub fn new(
max_size: usize,
max_duration: Duration,
channel_size: usize
) -> (Sender<Command<K, I>>, MultiBufBatchChannel<K, I>)
[src]
max_size: usize,
max_duration: Duration,
channel_size: usize
) -> (Sender<Command<K, I>>, MultiBufBatchChannel<K, I>)
Crates new instance with given maximum batch size (max_size
) and maximum duration (max_duration
) that
batch can last 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 Command
s.
Panics if max_size == 0
.
pub fn with_producer_thread(
max_size: usize,
max_duration: Duration,
channel_size: usize,
producer: impl FnOnce(Sender<Command<K, I>>) + Send + 'static
) -> MultiBufBatchChannel<K, I>
[src]
max_size: usize,
max_duration: Duration,
channel_size: usize,
producer: impl FnOnce(Sender<Command<K, I>>) + Send + 'static
) -> MultiBufBatchChannel<K, I>
Calls producer
closure with Sender
end of the channel in a newly started thread and
returns MultiBufBatchChannel
connected to that Sender
.
pub fn next<'i>(&'i mut self) -> Result<(K, Drain<I>), EndOfStreamError>
[src]
Gets next ready batch as pair of batch stream key K
and Drain
iterator of its items.
This call will block until one of the batches becomes ready.
When the Sender
end has dropped, this method returns with Err(EndOfStreamError)
after all
outstanding items were flushed.
pub fn outstanding(&self) -> impl Iterator<Item = &K>
[src]
Lists keys of outstanding batches.
pub fn clear(&mut self, key: &K)
[src]
Starts new batch dropping all buffered items.
pub fn drain(&mut self, key: &K) -> Option<Drain<I>>
[src]
Starts new batch by draining all buffered items.
pub fn flush(&mut self) -> Vec<(K, Vec<I>)>
[src]
Flushes all outstanding batches starting from oldest.
pub fn get(&self, key: &K) -> Option<&[I]>
[src]
Returns slice of internal item buffer of given outstanding batch.
pub fn clear_cache(&mut self)
[src]
Drops cached batch buffers.
pub fn stats(&self) -> Stats
[src]
Provides usage statistics.
pub fn split(self) -> (MultiBufBatch<K, I>, Receiver<Command<K, I>>)
[src]
Splits into MultiBufBatch
item buffer and channel Receiver
end.
Trait Implementations
Auto Trait Implementations
impl<K, I> RefUnwindSafe for MultiBufBatchChannel<K, I> where
I: RefUnwindSafe,
K: RefUnwindSafe,
I: RefUnwindSafe,
K: RefUnwindSafe,
impl<K, I> Send for MultiBufBatchChannel<K, I> where
I: Send,
K: Send,
I: Send,
K: Send,
impl<K, I> Sync for MultiBufBatchChannel<K, I> where
I: Send + Sync,
K: Send + Sync,
I: Send + Sync,
K: Send + Sync,
impl<K, I> Unpin for MultiBufBatchChannel<K, I> where
I: Unpin,
K: Unpin,
I: Unpin,
K: Unpin,
impl<K, I> UnwindSafe for MultiBufBatchChannel<K, I> where
I: RefUnwindSafe + UnwindSafe,
K: RefUnwindSafe + UnwindSafe,
I: RefUnwindSafe + UnwindSafe,
K: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,