Skip to content

feat: add js feature and wasm support via web_time crate#50

Open
niclashoyer wants to merge 1 commit intomoka-rs:v0.11.xfrom
hoyerdigital:wasm-js
Open

feat: add js feature and wasm support via web_time crate#50
niclashoyer wants to merge 1 commit intomoka-rs:v0.11.xfrom
hoyerdigital:wasm-js

Conversation

@niclashoyer
Copy link
Copy Markdown

@niclashoyer niclashoyer commented Jun 8, 2025

This adds experimental support for wasm/js using the web_time crate.

As wasm32-unknown-unknown does not directly support threads, I had problems getting sync to compile. So this currently just works for unsync.

A new feature js is introduced that enables the necessary dependencies. Tests need to be run with wasm-pack:

wasm-pack test --node --no-default-features --features js

@niclashoyer
Copy link
Copy Markdown
Author

niclashoyer commented Jun 8, 2025

On a side note: it may be possible to transparently support wasm by using web_time::* instead of of std::time where needed, as it automatically falls back to std::time on supported targets. This would remove the need for the js feature, but also introduce some magic around the web_time dependency.

@doraeric
Copy link
Copy Markdown

I am also looking for wasm support from moka and found this PR. I think it can be compiled to different targets based on target_arch just like opendal.

https://github.com/apache/opendal/blob/8332367dd7629bebc7759a11a5bbbd941dd060e9/core/core/src/raw/time.rs#L27-L30

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
pub use std::time::{Instant, SystemTime};
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub use web_time::{Instant, SystemTime};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants