pub struct Batch<T, Request>where
T: Service<BatchControl<Request>>,{ /* private fields */ }
Expand description
Allows batch processing of requests.
See the crate documentation for more details.
Implementations§
Source§impl<T, Request> Batch<T, Request>
impl<T, Request> Batch<T, Request>
Sourcepub fn new(
service: T,
max_items_in_batch: usize,
max_batches: impl Into<Option<usize>>,
max_latency: Duration,
) -> Self
pub fn new( service: T, max_items_in_batch: usize, max_batches: impl Into<Option<usize>>, max_latency: Duration, ) -> Self
Creates a new Batch
wrapping service
.
The wrapper is responsible for telling the inner service when to flush a batch of requests. These parameters control this policy:
max_items_in_batch
gives the maximum number of items per batch.max_batches
is an upper bound on the number of batches in the queue, and the number of concurrently executing batches. If this isNone
, we use the current number ofrayon
threads. The number of batches in the queue is also limited by [QUEUE_BATCH_LIMIT
].max_latency
gives the maximum latency for a batch item to start verifying.
The default Tokio executor is used to run the given service, which means that this method must be called while on the Tokio runtime.
Sourcepub fn pair(
service: T,
max_items_in_batch: usize,
max_batches: impl Into<Option<usize>>,
max_latency: Duration,
) -> (Self, Worker<T, Request>)
pub fn pair( service: T, max_items_in_batch: usize, max_batches: impl Into<Option<usize>>, max_latency: 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.
Sourcepub fn register_worker(&mut self, worker_handle: JoinHandle<()>)
pub fn register_worker(&mut self, worker_handle: JoinHandle<()>)
Ask the Batch
to monitor the spawned worker task’s JoinHandle
.
Only used when the task is spawned on the tokio runtime.
Trait Implementations§
Source§impl<T, Request> Service<Request> for Batch<T, Request>
impl<T, Request> Service<Request> for Batch<T, Request>
Source§type Response = <T as Service<BatchControl<Request>>>::Response
type Response = <T as Service<BatchControl<Request>>>::Response
Source§type Future = ResponseFuture<<T as Service<BatchControl<Request>>>::Future>
type Future = ResponseFuture<<T as Service<BatchControl<Request>>>::Future>
Auto Trait Implementations§
impl<T, Request> Freeze for Batch<T, Request>
impl<T, Request> !RefUnwindSafe for Batch<T, Request>
impl<T, Request> Send for Batch<T, Request>
impl<T, Request> Sync for Batch<T, Request>
impl<T, Request> Unpin for Batch<T, Request>
impl<T, Request> !UnwindSafe for Batch<T, Request>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T, Request> ServiceExt<Request> for T
impl<T, Request> ServiceExt<Request> for T
Source§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
Source§fn ready_and(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready_and(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
ServiceExt::ready
method insteadSource§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
Source§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service
, calling with the providing request once it is ready.Source§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read moreSource§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read moreSource§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read moreSource§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more