static DELAY: [Duration; 3] = [Duration::from_millis(1), Duration::from_millis(2), Duration::from_millis(5)]; let mut tries = 0; let t = loop { match context.sql_pool.begin().await { Ok(t) => break Ok(t), Err(e) if tries == 3 => break Err(e), _ => { tokio::time::sleep(DELAY[tries]).await; } } tries += 1; }?;