Skip to content
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

Instant::now does not work in Web Workers #12

Open
knpwrs opened this issue Sep 20, 2020 · 2 comments
Open

Instant::now does not work in Web Workers #12

knpwrs opened this issue Sep 20, 2020 · 2 comments

Comments

@knpwrs
Copy link

knpwrs commented Sep 20, 2020

This library was working excellently until I tried to port some code I wrote to run in a web worker rather than in the main process. window does not exist in web workers, so web_sys::window() fails. That said, self.performance() is a thing in web workers so I think this module should be able to be updated to work in all browser environments.

This is the behavior I'm seeing using this module in a web worker: rustwasm/wasm-bindgen#1046

EDIT: To be specific, Instant::now() is not working inside of web workers because web_sys::window() does not work there. I'm hoping there's still a way to somehow access self.performance.now() inside a web worker using this module.

@knpwrs
Copy link
Author

knpwrs commented Sep 20, 2020

The gloo project had to fix a similar issue: rustwasm/gloo#56

I'm not sure how much work it would be to implement a similar solution here. It seems as though web_sys only directly supports performance off of web_sys::window() and not web_sys::global().

@knpwrs knpwrs changed the title Does not work in Web Workers Instant::now does not work in Web Workers Sep 20, 2020
@knpwrs
Copy link
Author

knpwrs commented Sep 21, 2020

There is a similar issue opened for the web-sys crate: rustwasm/wasm-bindgen#1752

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

No branches or pull requests

1 participant