Add retry_future2 and use it in iOS api client

This commit is contained in:
Joakim Hulthe committed 2026-09-24 17:25:23 +02:00
1 parent c8fac8f7ba
commit f4760cf048
2 files changed
+28 -2

No files matched your search

+2 -2
View File
@@ -16,7 +16,7 @@ use mullvad_types::access_method::Id;
use response::ApiResponse;
use retry_strategy::RetryStrategy;
use std::{future::Future, sync::Arc};
use talpid_future::retry::retry_future;
use talpid_future::retry::retry_future2;
mod access_method_resolver;
mod access_method_settings;
@@ -270,5 +270,5 @@ where
Ok(_) => false,
};
retry_future(future_factory, should_retry, retry_strategy.delays()).await
retry_future2(future_factory, should_retry, retry_strategy.delays()).await
}
+26
View File
@@ -28,6 +28,32 @@ pub async fn retry_future<
}
}
/// Retries a future until it should stop as determined by the retry function, or when
/// the iterator returns `None`. Unlike [`retry_future`], the future may not reference the function.
pub async fn retry_future2<
F: FnMut() -> O,
R: FnMut(&T) -> bool,
D: Iterator<Item = Duration>,
O: Future<Output = T>,
T,
>(
mut factory: F,
mut should_retry: R,
mut delays: D,
) -> T {
loop {
let current_result = factory().await;
if should_retry(&current_result)
&& let Some(delay) = delays.next()
{
sleep(delay).await;
continue;
}
return current_result;
}
}
/// Iterator that repeats the same interval, with an optional maximum no. of attempts.
pub struct ConstantInterval {
interval: Duration,