Skip to main content

SpeculationEngine

Struct SpeculationEngine 

Source
pub struct SpeculationEngine { /* private fields */ }
Expand description

Per-turn speculation engine. One instance per SessionPipeline; holds the JoinSet and the host budget. Drop = shutdown.

Implementations§

Source§

impl SpeculationEngine

Source

pub fn new( config: EnrichmentConfig, dispatcher: Arc<dyn PrefetchDispatcher>, ) -> Self

Build a fresh engine bound to a dispatcher. Settings come from config.enrichment.

Source

pub fn with_per_host_cap(self, cap: u32) -> Self

Build with an explicit per-host cap. Useful for tests that want cap = 1 to force serialisation.

Source

pub fn is_enabled(&self) -> bool

true when enrichment.enabled = false — host should skip all dispatch and not even build a plan.

Source

pub fn timeout(&self) -> Duration

Returns the configured wall-clock budget for one wait_within call.

Source

pub fn pending(&self) -> usize

Number of currently-spawned tasks (incl. pending ones from previous turns that have not been collected yet).

Source

pub async fn dispatch( &mut self, requests: Vec<PrefetchRequest>, ) -> Vec<PrefetchOutcome>

Schedule requests honouring max_parallel_prefetches and per-host caps. Requests rejected by either gate are reported as Skipped outcomes and not spawned.

Returns the immediately-known outcomes (skips). Settled / failed outcomes come back from Self::wait_within.

Source

pub async fn wait_within(&mut self) -> Vec<PrefetchOutcome>

Wait up to prefetch_timeout_ms collecting outcomes for tasks that complete in time. Tasks still pending stay in the JoinSet — their results arrive on the next wait_within (or get cancelled by shutdown).

The timeout is a global deadline for the whole call, not a per-task budget — N slow prefetches finishing one-by-one just under the threshold can no longer stall the response for N × prefetch_timeout_ms.

Returns Settled for every task that returned Ok(body), Failed for every Err(...). Skipped outcomes from the most recent dispatch call are not echoed here — the host already has them.

Source

pub async fn drain_pending(&mut self) -> Vec<PrefetchOutcome>

Best-effort drain of completed tasks without blocking.

Returns outcomes for every task that has already finished, leaves still-pending tasks alone. Lets the host call this on the next turn (or before each dispatch) to recover bodies that landed after the previous wait_within timed out, so they can still be written into the dedup cache instead of being silently lost on the next shutdown.

Source

pub async fn shutdown(&mut self)

Abort every still-pending task. Idempotent.

Trait Implementations§

Source§

impl Drop for SpeculationEngine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more