[fuchsia_async] Add impl WakeupTime for fuchsia_zircon::Duration Fixed: 87477 Change-Id: I98af0dffe8ae9f709ec048bd38ba36b612607653 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/613642 Commit-Queue: Ilya Yanok <yanok@google.com> Reviewed-by: Adam Perry <adamperry@google.com>
diff --git a/src/lib/fuchsia-async/src/runtime/mod.rs b/src/lib/fuchsia-async/src/runtime/mod.rs index 5d9a7d3..51aed3f 100644 --- a/src/lib/fuchsia-async/src/runtime/mod.rs +++ b/src/lib/fuchsia-async/src/runtime/mod.rs
@@ -61,6 +61,13 @@ } } +#[cfg(target_os = "fuchsia")] +impl WakeupTime for Duration { + fn into_time(self) -> Time { + Time::after(self) + } +} + impl DurationExt for std::time::Duration { fn after_now(self) -> Time { self.into_time() @@ -300,6 +307,17 @@ } } + #[cfg(target = "fuchsia")] + #[test] + fn can_use_zx_duration() { + let mut exec = LocalExecutor::new().unwrap(); + let start = Instant::now(); + let timer = Timer::new(Duration::from_millis(100)); + exec.run_singlethreaded(timer); + let end = Instant::now(); + assert!(end - start > std::time::Duration::from_millis(100)); + } + #[test] fn can_detect_stalls() { use std::sync::atomic::{AtomicU64, Ordering};