Skip to content

Commit

Permalink
[Akaze] Do not crash in web workers when querying performance (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanemagnenat authored Jul 20, 2023
1 parent 8575691 commit 82a25ee
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions akaze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ impl Instant {
fn now() -> Self {
#[cfg(feature = "web-sys")]
{
Self(web_sys::window().unwrap().performance().unwrap().now())
Self(
web_sys::window()
.and_then(|w| w.performance())
.map_or(0., |p| p.now()),
)
}
#[cfg(not(feature = "web-sys"))]
{
Expand All @@ -37,9 +41,7 @@ impl Instant {
fn elapsed(&self) -> std::time::Duration {
#[cfg(feature = "web-sys")]
{
std::time::Duration::from_secs_f64(
(web_sys::window().unwrap().performance().unwrap().now() - self.0) * 0.001,
)
std::time::Duration::from_secs_f64((Self::now().0 - self.0) * 0.001)
}
#[cfg(not(feature = "web-sys"))]
{
Expand Down

0 comments on commit 82a25ee

Please sign in to comment.