use std::time::Duration;
pub async fn sleep(duration: Duration) {
#[cfg(not(target_family = "wasm"))]
tokio::time::sleep(duration).await;
#[cfg(target_family = "wasm")]
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)]
mod tests {
use matrix_sdk_test_macros::async_test;
use super::*;
#[cfg(target_family = "wasm")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[async_test]
async fn test_sleep() {
sleep(Duration::from_millis(1)).await;
}
}