Skip to content

Commit

Permalink
Use the browser-only js-sys workaround only when actually targeting a…
Browse files Browse the repository at this point in the history
… browser (#1005) (#1008)

wasi runtimes do provide a SystemTime implementation, see
https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi-common/src/clocks.rs
  • Loading branch information
wosc authored Mar 29, 2023
1 parent 3b273fa commit 3597479
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions opentelemetry-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ pub mod time {
use std::time::SystemTime;

#[doc(hidden)]
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(
not(target_arch = "wasm32"),
all(target_arch = "wasm32", target_os = "wasi")
))]
pub fn now() -> SystemTime {
SystemTime::now()
}

#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
pub fn now() -> SystemTime {
SystemTime::UNIX_EPOCH + std::time::Duration::from_millis(js_sys::Date::now() as u64)
}
Expand Down

0 comments on commit 3597479

Please sign in to comment.