Skip to content

Commit

Permalink
fixup: fix: don't use tokio timeout and sleep on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
maan2003 committed Jan 22, 2025
1 parent 613f376 commit dbf2e65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 7 additions & 2 deletions crates/matrix-sdk-common/src/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ use std::time::Duration;
/// non-wasm32 targets.
pub async fn sleep(duration: Duration) {
#[cfg(not(target_arch = "wasm32"))]
#[allow(clippy::disallowed_methods)]
tokio::time::sleep(duration).await;

#[cfg(target_arch = "wasm32")]
gloo_timers::future::TimeoutFuture::new(duration.as_millis() as u32).await;
gloo_timers::future::TimeoutFuture::new(u32::try_from(duration.as_millis()).unwrap_or_else(
|_| {
tracing::error!("Sleep duration too long, sleeping for u32::MAX ms");
u32::MAX
},
))
.await;
}

#[cfg(test)]
Expand Down
1 change: 0 additions & 1 deletion crates/matrix-sdk-common/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ where
F: Future<Output = T>,
{
#[cfg(not(target_arch = "wasm32"))]
#[allow(clippy::disallowed_methods)]
return tokio_timeout(duration, future).await.map_err(|_| ElapsedError(()));

#[cfg(target_arch = "wasm32")]
Expand Down

0 comments on commit dbf2e65

Please sign in to comment.