pub struct Batch<T, Request>where
T: Service<BatchControl<Request>>,{ /* private fields */ }Expand description
Handle for submitting requests to a batch worker.
Each Batch handle communicates with a single background worker over a
shared channel. Handles are cheap to Clone – every clone sends to the
same worker, so you can hand them to multiple tasks.
See the module documentation for the full lifecycle and error semantics.
Implementations§
Source§impl<T, Request> Batch<T, Request>
impl<T, Request> Batch<T, Request>
Sourcepub fn new(service: T, size: usize, time: Duration) -> Self
pub fn new(service: T, size: usize, time: Duration) -> Self
Creates a new Batch wrapping service.
size is the maximum number of items per batch and time is the
maximum duration before a batch is flushed. The worker flushes
whichever limit is hit first.
The background worker is spawned on the default Tokio executor, so this method must be called while on the Tokio runtime.
Sourcepub fn pair(
service: T,
size: usize,
time: Duration,
) -> (Self, Worker<T, Request>)
pub fn pair( service: T, size: usize, time: Duration, ) -> (Self, Worker<T, Request>)
Creates a new Batch wrapping service, but returns the background worker.
This is useful if you do not want to spawn directly onto the tokio
runtime but instead want to use your own executor. This will return the
Batch and the background Worker that you can then spawn.