Skip to main content

StreamTimeouts

Struct StreamTimeouts 

Source
#[non_exhaustive]
pub struct StreamTimeouts { pub setup: Option<Duration>, pub idle: Option<Duration>, }
Expand description

Time bounds for a streaming request, enforced above the transport.

A streaming response has no total deadline (a long answer is not a failure), but a dead endpoint or a stalled connection must not hang a caller forever. Two bounds catch that:

  • setup: from sending the request until the response status and headers arrive.
  • idle: the longest wait for a body chunk, the first one included. Only waiting on the transport counts: for each chunk, the clock starts when the reader polls and the chunk is not ready yet, so the time before the reader’s first poll or between its polls does not count.

send enforces both on any HttpTransport; provider crates call it for their streaming requests (non-streaming requests carry a whole-exchange HttpRequest::timeout instead). Expiry fails with a TransportErrorKind::Timeout error, which providers surface as allama::Error::Timeout, retryable and fallback-eligible.

The defaults (DEFAULT_SETUP, DEFAULT_IDLE) are deliberately generous: they detect dead connections, not slow models. Reasoning models can stay silent for minutes before their first token, and an idle bound that cuts such a stream off bills the reasoning and returns nothing. Tighter, workload-specific bounds belong in allama::wrappers::TimeoutProvider, which wraps the decoded stream and fires first when its limits are shorter. It can also bound a stream’s total duration (TimeoutPolicy::stream_total), which this transport layer leaves to the application.

Timers come from futures-timer (the same timers TimeoutProvider uses), so the bounds work on any async runtime and, through the browser or worker setTimeout, on wasm32-unknown-unknown.

use std::time::Duration;
use allama_http::StreamTimeouts;

let tight = StreamTimeouts::default().idle(Some(Duration::from_secs(30)));
assert_eq!(tight.setup, Some(StreamTimeouts::DEFAULT_SETUP));

// A local server that may load a model first: no bounds at all.
let local = StreamTimeouts::unbounded();
assert_eq!((local.setup, local.idle), (None, None));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§setup: Option<Duration>

Bound on the wait for the response status and headers.

§idle: Option<Duration>

Bound on the wait for each body chunk, the first one included, counted from the reader’s poll that finds the chunk not ready.

Implementations§

Source§

impl StreamTimeouts

Source

pub const DEFAULT_SETUP: Duration

Default setup bound: 120 s, the same budget the provider crates give a whole non-streaming call. A streaming endpoint normally answers with headers right away and keeps the model’s latency for the body.

Source

pub const DEFAULT_IDLE: Duration

Default idle bound: 300 s. Longer than a non-streaming call’s whole default budget on purpose: streaming is how callers reach reasoning models that think for minutes before their first token, and not every endpoint sends keep-alive events meanwhile.

Source

pub const fn unbounded() -> Self

No bounds: the stream may wait forever (for example for a local server that loads the model before answering).

Source

pub const fn setup(self, timeout: Option<Duration>) -> Self

Set (or clear) the setup bound.

Source

pub const fn idle(self, timeout: Option<Duration>) -> Self

Set (or clear) the idle bound.

Source

pub async fn send<T>( self, transport: &T, request: HttpRequest, ) -> Result<HttpResponse, TransportError>
where T: HttpTransport + ?Sized,

Send request through transport with these bounds: the response headers must arrive within setup, and its body then fails when no chunk arrives within idle.

Expiry drops the transport’s future or body, cancelling the request.

§Errors

The transport’s errors, or a TransportErrorKind::Timeout error when the setup bound expires. An idle expiry is the body’s last item.

Trait Implementations§

Source§

impl Clone for StreamTimeouts

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for StreamTimeouts

Source§

impl Debug for StreamTimeouts

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for StreamTimeouts

Source§

impl Eq for StreamTimeouts

Source§

impl PartialEq for StreamTimeouts

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StreamTimeouts

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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