pub trait RequestGate: Send + Sync {
// Required methods
fn before_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 GatedRequest,
) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn after_response(&self, readings: &[QuotaReading]);
// Provided method
fn request_ended(&self) { ... }
}Expand description
What a caller installs to wait or stop between any two requests a store call sends.
It holds the caller’s policy; the store holds none. A wait — before_request not yet
returned — holds that source’s next request and nothing else: a source asks it inline, so
another source’s call, and another call to the same engine, go on. A refusal —
before_request answering Err — makes the source send nothing more in that call: what
already landed is answered as it is today, the item in flight as a failure part way
through it, and every later item of a batch with the refusal, nothing sent for it.
One request is exempt: a stdio peer’s initialize handshake. The engine sends it once,
while the engine is being built, before Engine::with_request_gate can install a gate, and
it costs no backend quota. Every method sent a peer after the gate is installed is asked of
it first.
Every admitted request ends, exactly once. For each before_request that answered Ok
the gate is told request_ended once, whatever became of the
request — answered with readings or without, failed in transport before any header arrived,
a write to a source’s own files, or its future dropped mid-flight by a cancellation or by a
sibling failing beside it. A request before_request refused is never ended, and neither is
one whose before_request future was itself dropped before it answered: a gate that takes
something inside before_request gives it back on its own drop path there.
Required Methods§
Sourcefn before_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 GatedRequest,
) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn before_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 GatedRequest,
) -> Pin<Box<dyn Future<Output = Result<(), SourceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Answer whether request may be sent now — after as long a wait as the caller’s policy
asks for — or why not.
§Errors
The refusal the source is to fail its call with, sending nothing more.
Sourcefn after_response(&self, readings: &[QuotaReading])
fn after_response(&self, readings: &[QuotaReading])
What the response to a request said about each window it named.
Provided Methods§
Sourcefn request_ended(&self)
fn request_ended(&self)
One request this gate admitted is over: nothing more of it will be sent or read, so a
gate may treat this as proof that it is no longer in flight — a slot it keeps per
request in flight can be given back. Delivered exactly once per admitted request, after
any after_response its response carried, and never for a
request before_request refused. A gate that keeps no such count needs nothing here.
Implementations§
Source§impl dyn RequestGate
impl dyn RequestGate
Sourcepub async fn scope<F: Future>(gate: Arc<dyn RequestGate>, call: F) -> F::Output
pub async fn scope<F: Future>(gate: Arc<dyn RequestGate>, call: F) -> F::Output
Run call with gate answering every [<dyn RequestGate>::before] and
[<dyn RequestGate>::after] made inside it.
Sourcepub fn current() -> Option<Arc<dyn RequestGate>>
pub fn current() -> Option<Arc<dyn RequestGate>>
The gate of the call in progress, if any — what a call that spawns work of its own
carries into it with [Self::scope].
Sourcepub async fn before(
request: &GatedRequest,
) -> Result<AdmittedRequest, SourceError>
pub async fn before( request: &GatedRequest, ) -> Result<AdmittedRequest, SourceError>
Ask the gate of the call in progress, if any, whether request may be sent now — a
source calls this immediately before sending each request, and holds the answer until
the request is over: see AdmittedRequest. The admission ends at the gate that
admitted it, wherever it is dropped.
§Errors
The gate’s refusal, which admits nothing and is never ended; with no gate installed, never.
Sourcepub fn after(readings: &[QuotaReading])
pub fn after(readings: &[QuotaReading])
Tell the gate of the call in progress, if any, what a response said is left; with no gate installed, or no readings, nothing happens.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".