Skip to main content

executar_com_retry

Function executar_com_retry 

Source
pub async fn executar_com_retry<F, Fut, T>(
    chaves: &[ChaveApi],
    operacao: F,
) -> Result<T>
where F: Fn(String) -> Fut, Fut: Future<Output = Result<T, ErroContext7>>,
Expand description

Executes an API call with retry and key rotation.

Shuffles a local copy of the provided keys (random draw without replacement) and retries up to min(keys.len(), 5) times with exponential backoff: 500 ms → 1 s → 2 s.

Short-circuits immediately on parse errors (status 200 but JSON failed) — retrying with another key would not help in that case.

The closure receives an owned String (clone of the key) to satisfy the async move ownership requirement inside the future.