pub async fn timeout<F>(
duration: Duration,
future: F,
) -> Result<F::Output, Elapsed>where
F: Future,Expand description
Await future, returning Err(Elapsed) if it does not complete within
duration.
A cross-platform (native + wasm) replacement for tokio::time::timeout: rig’s
tokio dependency is built without the time feature, and tokio::time does
not function on wasm. This is built on futures_timer::Delay, which rig
already uses for SSE retry backoff.
On elapse the pending future is dropped (cancelled by drop); it gets no
chance to run cleanup beyond its own Drop. A zero or already-elapsed
duration still polls future once before electing Elapsed, and an absurdly
large duration may panic when added to Instant::now() inside the timer.
§Wasm
On browser wasm (wasm32-unknown-unknown) the futures-timer wasm-bindgen
(setTimeout) backend is selected automatically via a target-scoped
dependency, so the timer fires without depending on any cargo feature. (The
futures_timer::Delay SSE retry backoff relies on the same backend.)