Add wasm tests (#74)
This commit is contained in:
parent
2b2881a375
commit
5077768172
13 changed files with 92 additions and 29 deletions
37
src/deadline_support.rs
Normal file
37
src/deadline_support.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use std::time::Duration;
|
||||
|
||||
#[cfg(not(feature = "wasm32_web_time"))]
|
||||
pub use std::time::Instant;
|
||||
|
||||
/// WASM (browser) specific instant type.
|
||||
///
|
||||
/// This type is only available when the `wasm32_web_time` feature is enabled. In that
|
||||
/// case this is an alias for [`web_time::Instant`].
|
||||
#[cfg(feature = "wasm32_web_time")]
|
||||
pub use web_time::Instant;
|
||||
|
||||
/// Checks if a deadline was exeeded.
|
||||
pub fn deadline_exceeded(deadline: Option<Instant>) -> bool {
|
||||
#[allow(unreachable_code)]
|
||||
match deadline {
|
||||
Some(deadline) => {
|
||||
#[cfg(all(target_arch = "wasm32", not(feature = "wasm32_web_time")))]
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Instant::now() > deadline
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converst a duration into a deadline. This can be a noop on wasm
|
||||
#[allow(unused)]
|
||||
pub fn duration_to_deadline(add: Duration) -> Option<Instant> {
|
||||
#[allow(unreachable_code)]
|
||||
#[cfg(all(target_arch = "wasm32", not(feature = "wasm32_web_time")))]
|
||||
{
|
||||
return None;
|
||||
}
|
||||
Instant::now().checked_add(add)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue