similar/
deadline_support.rs1use std::time::Duration;
2
3#[cfg(not(feature = "wasm32_web_time"))]
4pub use std::time::Instant;
5
6#[cfg(feature = "wasm32_web_time")]
11pub use web_time::Instant;
12
13pub fn deadline_exceeded(deadline: Option<Instant>) -> bool {
15 #[allow(unreachable_code)]
16 match deadline {
17 Some(deadline) => {
18 #[cfg(all(target_arch = "wasm32", not(feature = "wasm32_web_time")))]
19 {
20 return false;
21 }
22 Instant::now() > deadline
23 }
24 None => false,
25 }
26}
27
28#[allow(unused)]
30pub fn duration_to_deadline(add: Duration) -> Option<Instant> {
31 #[allow(unreachable_code)]
32 #[cfg(all(target_arch = "wasm32", not(feature = "wasm32_web_time")))]
33 {
34 return None;
35 }
36 Instant::now().checked_add(add)
37}