mirror of
https://github.com/uuid-rs/uuid.git
synced 2025-10-01 15:01:05 +00:00
Fixing issue with Cloudflare Workers when using now(): "LinkError: WebAssembly.Instance(): Import #9 module="./index_bg.js" function="__wbg_now_dc6f7ce2227b5592" error: function import requires a callable"
Similar issue: https://github.com/rustwasm/gloo/pull/249
This commit is contained in:
parent
07052be44a
commit
b5f16b9e05
@ -262,17 +262,17 @@ 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;
|
||||
@ -280,7 +280,7 @@ fn now() -> (u64, 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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user