expression
Share one absolute timeout budget
Give sequential operations the same absolute deadline. The second operation has only the remaining budget, rather than receiving a fresh full timeout. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true true Common mistake: Resetting the request budget on every sub-operation.
Formal Syntax & Structure
rust syntaxrust
tokio::time::timeout_at(deadline, future).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread", start_paused = true)]async fn main() { use tokio::time::{timeout_at, sleep, Duration, Instant}; let limit = Instant::now() + Duration::from_secs(5); let a = timeout_at(limit, sleep(Duration::from_secs(2))).await; let b = timeout_at(limit, sleep(Duration::from_secs(8))).await; println!("{} {}", a.is_ok(), b.is_err());}