pub struct Batcher<P: Processor> { /* private fields */ }Expand description
Groups items to be processed in batches.
Takes inputs one at a time and sends them to a background worker task which groups them into
batches according to the specified BatchingPolicy and Limits, and processes them using
the provided Processor.
Cheap to clone. Cloned instances share the same background worker task.
§Drop
When the last instance of a Batcher is dropped, the worker task will be aborted (ungracefully
shut down).
If you want to shut down the worker gracefully, call WorkerHandle::shut_down().
Implementations§
Source§impl<P: Processor> Batcher<P>
impl<P: Processor> Batcher<P>
Sourcepub async fn add(
&self,
key: P::Key,
input: P::Input,
) -> BatchResult<P::Output, P::Error>
pub async fn add( &self, key: P::Key, input: P::Input, ) -> BatchResult<P::Output, P::Error>
Add an item to be batched and processed, and await the result.
Sourcepub fn worker_handle(&self) -> Arc<WorkerHandle>
pub fn worker_handle(&self) -> Arc<WorkerHandle>
Get a handle to the worker.
Trait Implementations§
Auto Trait Implementations§
impl<P> Freeze for Batcher<P>
impl<P> RefUnwindSafe for Batcher<P>
impl<P> Send for Batcher<P>
impl<P> Sync for Batcher<P>
impl<P> Unpin for Batcher<P>
impl<P> UnwindSafe for Batcher<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more