Skip to main content

deribit_http/
sleep_compat.rs

1//! Cross-platform async sleep for native and WASM targets
2//!
3//! This module provides a unified `sleep` function that uses `tokio::time::sleep`
4//! on native targets and `futures_timer::Delay` on WASM targets.
5
6use std::time::Duration;
7
8/// Asynchronously sleeps for the specified duration.
9///
10/// This function provides cross-platform async sleep functionality:
11/// - On native targets (with `native` feature): uses `tokio::time::sleep`
12/// - On WASM targets: uses `futures_timer::Delay`
13///
14/// # Arguments
15///
16/// * `duration` - The duration to sleep for
17#[cfg(feature = "native")]
18pub async fn sleep(duration: Duration) {
19    tokio::time::sleep(duration).await;
20}
21
22/// Asynchronously sleeps for the specified duration.
23///
24/// This function provides cross-platform async sleep functionality:
25/// - On native targets (with `native` feature): uses `tokio::time::sleep`
26/// - On WASM targets: uses `futures_timer::Delay`
27///
28/// # Arguments
29///
30/// * `duration` - The duration to sleep for
31#[cfg(not(feature = "native"))]
32pub async fn sleep(duration: Duration) {
33    futures_timer::Delay::new(duration).await;
34}