let big = std::time::Duration::from_secs(u64::MAX / 10); // This is a workaround since awaiting sleep(big) will never finish. #[rustfmt::skip]
tokio::select! {
biased;
_ = tokio::time::sleep(big) => {}
_ = tokio::time::sleep(std::time::Duration::from_nanos(1)) => {}
}
}
#[tokio::test] asyncfn drop_after_reschedule_at_new_scheduled_time() { use futures::poll;
tokio::time::pause();
let start = tokio::time::Instant::now();
letmut a = Box::pin(tokio::time::sleep(Duration::from_millis(5))); letmut b = Box::pin(tokio::time::sleep(Duration::from_millis(5))); letmut c = Box::pin(tokio::time::sleep(Duration::from_millis(10)));
let _ = poll!(&mut a); let _ = poll!(&mut b); let _ = poll!(&mut c);
#[tokio::test] asyncfn drop_from_wake() { use std::future::Future; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; use std::task::Context;
let panicked = Arc::new(AtomicBool::new(false)); let list: Arc<Mutex<Vec<Pin<Box<tokio::time::Sleep>>>>> = Arc::new(Mutex::new(Vec::new()));
let arc_wake = Arc::new(DropWaker(panicked.clone(), list.clone())); let arc_wake = futures::task::waker(arc_wake);
tokio::time::pause();
{ letmut lock = list.lock().unwrap();
for _ in0..100 { letmut timer = Box::pin(tokio::time::sleep(Duration::from_millis(10)));
let _ = timer.as_mut().poll(&mut Context::from_waker(&arc_wake));
impl futures::task::ArcWake for DropWaker { fn wake_by_ref(arc_self: &Arc<Self>) { let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
*arc_self.1.lock().expect("panic in lock") = Vec::new()
}));
if result.is_err() {
arc_self.0.store(true, Ordering::SeqCst);
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.