pub struct BufferService<St, Req, Res, Err> { /* private fields */ }Expand description
A service that buffers requests while its wrapped service is not ready.
The service is ready while the buffer has room; it does not depend on the readiness of the wrapped service. Requests that arrive while the wrapped service is not ready, or while earlier requests are still waiting, are buffered and released in order. Each released request waits for the wrapped service’s readiness, then releases the next one before calling the wrapped service. The wrapped service must notify synchronously when a call consumes its capacity, as required by readiness caching.
The buffer size is a soft limit: callers that call without a readiness check, or after an outdated one, are still buffered. Queue capacity changes invalidate cached readiness for every pipeline sharing this service, including when a queued request is canceled.
Errors of the wrapped service’s readiness are returned to the waiting
request. Shutdown waits until all buffered requests have completed their
calls, unless cancel_on_shutdown is set, and
shuts down the wrapped service afterwards.
The default buffer capacity is 16 requests. A capacity of 0 is treated as 1.
Implementations§
Source§impl<St, Req, Res, Err> BufferService<St, Req, Res, Err>where
St: Clone + 'static,
impl<St, Req, Res, Err> BufferService<St, Req, Res, Err>where
St: Clone + 'static,
Sourcepub fn new(size: usize, service: PipelineState<St, Req, Res, Err>) -> Self
pub fn new(size: usize, service: PipelineState<St, Req, Res, Err>) -> Self
Creates a buffering service with the specified capacity.
Sourcepub fn cancel_on_shutdown(self) -> Self
pub fn cancel_on_shutdown(self) -> Self
Cancels pending buffered requests instead of releasing them on shutdown.