Skip to main content

RequestGate

Trait RequestGate 

Source
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]);
}
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.

Required Methods§

Source

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.

Source

fn after_response(&self, readings: &[QuotaReading])

What the response to a request said about each window it named.

Implementations§

Source§

impl dyn RequestGate

Source

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.

Source

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].

Source

pub async fn before(request: &GatedRequest) -> Result<(), 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.

§Errors

The gate’s refusal; with no gate installed, never.

Source

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".

Implementors§