forked from bitcoindevkit/rust-esplora-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdc7aed
commit f74ff21
Showing
3 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,25 @@ | ||
#[cfg(feature = "tokio")] | ||
pub use tokio::time::sleep; | ||
use std::time::Duration; | ||
|
||
pub trait Runtime { | ||
fn sleep(duration: Duration) -> impl std::future::Future<Output = ()> + Send; | ||
} | ||
|
||
pub struct DefaultRuntime; | ||
|
||
#[cfg(feature = "tokio")] | ||
impl Runtime for DefaultRuntime { | ||
async fn sleep(duration: Duration) { | ||
tokio::time::sleep(duration).await; | ||
} | ||
} | ||
|
||
#[cfg(feature = "async-std")] | ||
pub use async_std::task::sleep; | ||
pub struct AsyncStd; | ||
|
||
#[cfg(not(any(feature = "tokio", feature = "async-std")))] | ||
compile_error!("Either 'tokio' or 'async-std' feature must be enabled"); | ||
#[cfg(feature = "async-std")] | ||
impl Runtime for AsyncStd { | ||
async fn sleep(duration: Duration) { | ||
async_std::task::sleep(duration).await; | ||
} | ||
} |