[−][src]Struct multistream_batch::multi_buf_batch::MultiBufBatch
Collects items into multiple batches based on stream key.
A batch may become ready after collecting max_size
number of items or until max_duration
has elapsed
since first item was appended to the batch.
Batch item buffers are cached and reused to avoid allocations.
This base implementation does not handle actual awaiting for batch duration timeout.
Methods
impl<K, I> MultiBufBatch<K, I> where
K: Debug + Ord + Hash + Clone,
I: Debug,
[src]
K: Debug + Ord + Hash + Clone,
I: Debug,
pub fn new(max_size: usize, max_duration: Duration) -> MultiBufBatch<K, I>
[src]
Crates new instance with given maximum batch size (max_size
) and maximum duration (max_duration
) that
batch can last since first item appended to it.
Panics if max_size
== 0.
pub fn poll(&self) -> PollResult<K>
[src]
Checks if batch has reached one of its limits.
Returns:
PollResult::Ready(K)
- batch for stream keyK
has reached one of its limit and is ready to be consumed,PollResult::NotReady(None)
- batch is not ready yet and has no items appeded yet,PollResult::NotReady(Some(duration))
- batch is not ready yet but it will be ready after time duration due to duration limit.
pub fn append(&mut self, key: K, item: I)
[src]
Appends item to batch with given stream key.
It is an contract error to append batch that is ready according to self.poll()
.
Panics if batch has already reached its max_size
limit.
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]
Consumes batch by draining items from internal buffer.
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.
Trait Implementations
Auto Trait Implementations
impl<K, I> Send for MultiBufBatch<K, I> where
I: Send,
K: Send,
I: Send,
K: Send,
impl<K, I> Unpin for MultiBufBatch<K, I> where
I: Unpin,
K: Unpin,
I: Unpin,
K: Unpin,
impl<K, I> Sync for MultiBufBatch<K, I> where
I: Sync,
K: Sync,
I: Sync,
K: Sync,
impl<K, I> UnwindSafe for MultiBufBatch<K, I> where
I: RefUnwindSafe + UnwindSafe,
K: RefUnwindSafe + UnwindSafe,
I: RefUnwindSafe + UnwindSafe,
K: RefUnwindSafe + UnwindSafe,
impl<K, I> RefUnwindSafe for MultiBufBatch<K, I> where
I: RefUnwindSafe,
K: RefUnwindSafe,
I: RefUnwindSafe,
K: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,