fix: use native async recursion
Some checks failed
Security audit / security_audit (push) Waiting to run
Conventional Commits / Conventional Commits (push) Waiting to run
/ Flake Checker (push) Waiting to run
/ Check Nix Flake (push) Waiting to run
/ Build Nix package (push) Waiting to run
Unit tests / unit-tests (ubuntu-latest, beta) (push) Waiting to run
Unit tests / unit-tests (ubuntu-latest, nightly) (push) Waiting to run
Unit tests / unit-tests (ubuntu-latest, stable) (push) Waiting to run
Unit tests / unit-tests (windows-latest, 1.70.0) (push) Waiting to run
Unit tests / unit-tests (windows-latest, beta) (push) Waiting to run
Unit tests / unit-tests (windows-latest, nightly) (push) Waiting to run
Unit tests / unit-tests (windows-latest, stable) (push) Waiting to run
Unit tests (BSD) / unit-tests-freebsd (push) Has been cancelled
Unit tests (BSD) / unit-tests-netbsd (push) Has been cancelled
Unit tests (BSD) / unit-tests-openbsd (push) Has been cancelled
Unit tests / unit-tests (macos-latest, 1.70.0) (push) Has been cancelled
Unit tests / unit-tests (macos-latest, beta) (push) Has been cancelled
Unit tests / unit-tests (macos-latest, nightly) (push) Has been cancelled
Unit tests / unit-tests (macos-latest, stable) (push) Has been cancelled
Unit tests / unit-tests (ubuntu-latest, 1.70.0) (push) Has been cancelled

Rust 1.77.0 added async recursion, we use that instead of the crate.
This requires a slight rewrite to heap pin the return value of the
closure so the function state doesn't grow.

Fix: #9
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2024-09-05 08:31:33 +02:00
parent 3f632969a9
commit 473986588d
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE
3 changed files with 7 additions and 16 deletions

12
Cargo.lock generated
View file

@ -100,17 +100,6 @@ version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "async-recursion"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
]
[[package]] [[package]]
name = "async-stream" name = "async-stream"
version = "0.3.5" version = "0.3.5"
@ -1122,7 +1111,6 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
name = "nix-weather" name = "nix-weather"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"async-recursion",
"clap", "clap",
"clap_complete", "clap_complete",
"clap_mangen", "clap_mangen",

View file

@ -16,7 +16,6 @@ publish = false
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
async-recursion = "1.0.5"
clap = { version = "4.5.1", features = ["cargo"] } clap = { version = "4.5.1", features = ["cargo"] }
console-subscriber = "0.2.0" console-subscriber = "0.2.0"
dns-lookup = "2.0.4" dns-lookup = "2.0.4"

View file

@ -5,7 +5,6 @@
use std::time::Duration; use std::time::Duration;
use async_recursion::async_recursion;
use reqwest::Client; use reqwest::Client;
use tokio::time::sleep; use tokio::time::sleep;
@ -13,7 +12,6 @@ use log;
const MAX_SLIDE: u64 = 1000; const MAX_SLIDE: u64 = 1000;
#[async_recursion]
pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) -> usize { pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) -> usize {
let response = client let response = client
.head(format!("https://{domain}/{hash}.narinfo")) .head(format!("https://{domain}/{hash}.narinfo"))
@ -30,7 +28,13 @@ pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) ->
// so we do this instead. // so we do this instead.
log::trace!("rate limited! {slide}"); log::trace!("rate limited! {slide}");
sleep(Duration::from_millis(slide)).await; sleep(Duration::from_millis(slide)).await;
nar_exists(client, domain, hash, std::cmp::min(slide * 2, MAX_SLIDE)).await Box::pin(nar_exists(
client,
domain,
hash,
std::cmp::min(slide * 2, MAX_SLIDE),
))
.await
} }
} }
} }