Struct Buffer
pub struct Buffer<Req, F> { /* private fields */ }
Adds an mpsc buffer in front of an inner service.
See the module documentation for more details.
Implementations
impl<Req, F> Buffer<Req, F>
where
F: 'static,
fn new<S>(service: S, bound: usize) -> Self where S: Service<Req, Future = F> + Send + 'static, F: Send, S::Error: Into<BoxError> + Send + Sync, Req: Send + 'static,Creates a new
Bufferwrappingservice.boundgives the maximal number of requests that can be queued for the service before backpressure is applied to callers.The default Tokio executor is used to run the given service, which means that this method must be called while on the Tokio runtime.
A note on choosing a
boundWhen
Buffer's implementation ofpoll_readyreturnsPoll::Ready, it reserves a slot in the channel for the forthcomingcall. However, if this call doesn't arrive, this reserved slot may be held up for a long time. As a result, it's advisable to setboundto be at least the maximum number of concurrent requests theBufferwill see. If you do not, all the slots in the buffer may be held up by futures that have just calledpoll_readybut will not issue acall, which prevents other senders from issuing new requests.fn pair<S>(service: S, bound: usize) -> (Self, Worker<S, Req>) where S: Service<Req, Future = F> + Send + 'static, F: Send, S::Error: Into<BoxError> + Send + Sync, Req: Send + 'static,Creates a new
Bufferwrappingservice, 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
Bufferand the backgroundWorkerthat you can then spawn.
Trait Implementations
impl<Req, F> Clone for Buffer<Req, F>
where
Req: Send + 'static,
F: Send + 'static,
fn clone(&self) -> Self
impl<Req, Rsp, F, E> Service<Req> for Buffer<Req, F>
where
F: Future<Output = Result<Rsp, E>> + Send + 'static,
E: Into<BoxError>,
Req: Send + 'static,
type Response = Rsp;type Error = Box<dyn Error + Sync + Send>;type Future = ResponseFuture<F>;fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>fn call(&mut self, request: Req) -> Self::Future
impl<Req: Debug, F: Debug> Debug for Buffer<Req, F>
fn fmt(&self, f: &mut Formatter<'_>) -> Result