Skip to content

Commit bd46422

Browse files
committed
Remove hard dependency on async-std, allow selecting tokio or async-std
1 parent 1f4acad commit bd46422

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ bitcoin = { version = "0.32", features = ["serde", "std"], default-features = fa
2222
hex = { version = "0.2", package = "hex-conservative" }
2323
log = "^0.4"
2424
minreq = { version = "2.11.0", features = ["json-using-serde"], optional = true }
25-
reqwest = { version = "0.11", features = ["json"], default-features = false, optional = true }
26-
async-std = { version = "1.13.0", optional = true }
25+
reqwest = { version = "0.12", features = ["json"], default-features = false, optional = true }
26+
27+
# async runtime
28+
async-std = { version = "1.13", optional = true }
29+
tokio = { version = "1.40", features = ["time"], optional = true }
2730

2831
[dev-dependencies]
2932
serde_json = "1.0"
@@ -38,7 +41,11 @@ blocking-https = ["blocking", "minreq/https"]
3841
blocking-https-rustls = ["blocking", "minreq/https-rustls"]
3942
blocking-https-native = ["blocking", "minreq/https-native"]
4043
blocking-https-bundled = ["blocking", "minreq/https-bundled"]
41-
async = ["async-std", "reqwest", "reqwest/socks"]
44+
45+
tokio = ["dep:tokio", "async"]
46+
async-std = ["dep:async-std", "async"]
47+
48+
async = ["reqwest", "reqwest/socks"]
4249
async-https = ["async", "reqwest/default-tls"]
4350
async-https-native = ["async", "reqwest/native-tls"]
4451
async-https-rustls = ["async", "reqwest/rustls-tls"]

src/async.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
//! Esplora by way of `reqwest` HTTP client.
1313
14-
use async_std::task;
1514
use std::collections::HashMap;
1615
use std::str::FromStr;
1716

@@ -434,7 +433,7 @@ impl AsyncClient {
434433
loop {
435434
match self.client.get(url).send().await? {
436435
resp if attempts < self.max_retries && is_status_retryable(resp.status()) => {
437-
task::sleep(delay).await;
436+
crate::runtime::sleep(delay).await;
438437
attempts += 1;
439438
delay *= 2;
440439
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub mod api;
7777
pub mod r#async;
7878
#[cfg(feature = "blocking")]
7979
pub mod blocking;
80+
#[cfg(feature = "async")]
81+
pub mod runtime;
8082

8183
pub use api::*;
8284
#[cfg(feature = "blocking")]

src/runtime.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(feature = "tokio")]
2+
pub use tokio::time::sleep;
3+
4+
#[cfg(feature = "async-std")]
5+
pub use async_std::task::sleep;
6+
7+
#[cfg(not(any(feature = "tokio", feature = "async-std")))]
8+
compile_error!("Either 'tokio' or 'async-std' feature must be enabled");

0 commit comments

Comments
 (0)