Skip to content

Commit

Permalink
Fixing issue with Cloudflare Workers when using now(): "LinkError: We…
Browse files Browse the repository at this point in the history
…bAssembly.Instance(): Import uuid-rs#9 module="./index_bg.js" function="__wbg_now_dc6f7ce2227b5592" error: function import requires a callable"

Similar issue: rustwasm/gloo#249
  • Loading branch information
kmusick committed Jun 21, 2023
1 parent 07052be commit b5f16b9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,25 @@ pub(crate) const fn decode_unix_timestamp_millis(uuid: &Uuid) -> u64 {
millis
}

#[cfg(all(feature = "std", feature = "js", target = "wasm32-unknown-unknown"))]
#[cfg(all(feature = "std", feature = "js", all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown")))]
fn now() -> (u64, u32) {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = Date)]
fn now() -> f64;
#[wasm_bindgen(js_namespace = Date, catch)]
fn now() -> Result<f64, JsValue>;
}

let now = now();
let now = now().unwrap_throw();

let secs = (now / 1_000.0) as u64;
let nanos = ((now % 1_000.0) * 1_000_000.0) as u32;

dbg!((secs, nanos))
}

#[cfg(all(feature = "std", any(not(feature = "js"), not(target = "wasm32-unknown-unknown"))))]
#[cfg(all(feature = "std", any(not(feature = "js"), not(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown")))))]
fn now() -> (u64, u32) {
let dur = std::time::SystemTime::UNIX_EPOCH
.elapsed()
Expand Down

0 comments on commit b5f16b9

Please sign in to comment.