type State = Buffer<BoxService<Request, Response, BoxError>, Request>;
Aliased Type§
struct State { /* private fields */ }
Implementations
§impl<T, Request> Buffer<T, Request>
impl<T, Request> Buffer<T, Request>
pub fn new(service: T, bound: usize) -> Buffer<T, Request>
pub fn new(service: T, bound: usize) -> Buffer<T, Request>
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>)
pub fn pair( service: T, bound: usize, ) -> (Buffer<T, Request>, Worker<T, Request>)
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.