Type Alias State

Source
type State = Buffer<BoxService<Request, Response, BoxError>, Request>;

Aliased Type§

struct State { /* private fields */ }

Implementations

§

impl<T, Request> Buffer<T, Request>
where T: Service<Request>, <T as Service<Request>>::Error: Into<Box<dyn Error + Send + Sync>>,

pub fn new(service: T, bound: usize) -> Buffer<T, Request>
where T: Send + 'static, <T as Service<Request>>::Future: Send, <T as Service<Request>>::Error: Send + Sync, Request: Send + 'static,

Creates a new [Buffer] wrapping service.

bound gives 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 bound

When [Buffer]’s implementation of poll_ready returns Poll::Ready, it reserves a slot in the channel for the forthcoming call. 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 set bound to be at least the maximum number of concurrent requests the [Buffer] will see. If you do not, all the slots in the buffer may be held up by futures that have just called poll_ready but will not issue a call, which prevents other senders from issuing new requests.

pub fn pair( service: T, bound: usize, ) -> (Buffer<T, Request>, Worker<T, Request>)
where T: Send + 'static, <T as Service<Request>>::Error: Send + Sync, Request: Send + 'static,

Creates a new [Buffer] 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 [Buffer] and the background Worker that you can then spawn.

Trait Implementations

§

impl<T, Request> Clone for Buffer<T, Request>
where T: Service<Request>,

§

fn clone(&self) -> Buffer<T, Request>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T, Request> Debug for Buffer<T, Request>
where T: Debug + Service<Request>, Request: Debug, <T as Service<Request>>::Future: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T, Request> Service<Request> for Buffer<T, Request>
where T: Service<Request>, <T as Service<Request>>::Error: Into<Box<dyn Error + Send + Sync>>,

§

type Response = <T as Service<Request>>::Response

Responses given by the service.
§

type Error = Box<dyn Error + Send + Sync>

Errors produced by the service.
§

type Future = ResponseFuture<<T as Service<Request>>::Future>

The future response value.
§

fn poll_ready( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<(), <Buffer<T, Request> as Service<Request>>::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
§

fn call( &mut self, request: Request, ) -> <Buffer<T, Request> as Service<Request>>::Future

Process the request and return the response asynchronously. Read more