-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make WASM polyfilled Instant work in web workers. #75
base: main
Are you sure you want to change the base?
Conversation
6c8ac68
to
44d5aed
Compare
This is blocked on rustwasm/wasm-bindgen#3530. |
44d5aed
to
8b68e54
Compare
8b68e54
to
8bb15fe
Compare
The Shameless plug: I recommend you to use |
@daxpedda thanks for the review. Yes so we I did not consider cross-thread compatibility, as the thread story on the web is shaky anyway, and we do not have use cases for WASI at the moment. Also, I aimed for very simple implementation, as simplicity has value as well. But I'm not against using a third-party crate that does the job more thoroughly. Let's see what the others think. @vadixidav, @xd009642 what do you think? Context is: support timing under WASM for Akaze performance instrumentation. Will have no effect on non-WASM targets. |
|
Thanks for the explanation! Let's see what the others think about adding this dependency. |
I don't have an objection to it given it's just for the wasm target |
i just had the following error in instant about 10% of the time in a web worker. panicked at 'failed to get performance from global object: JsValue(undefined)
instant-0.1.12/src/wasm.rs:137:14 this crate works perfectly as a replacement. great work! |
The polyfill for
std::Instant
I added for WASM depends on window, but that later is not available in web workers. This PR uses the worker global scope, if present, and attempts to use window otherwise. If nothing works, it returns 0 instead of panicking.