(ms: u64, cancel: CancellationToken)
| 12 | pub struct SleepCancelled; |
| 13 | |
| 14 | pub async fn sleep_with_cancel(ms: u64, cancel: CancellationToken) -> Result<(), SleepCancelled> { |
| 15 | let duration = Duration::from_millis(ms.min(RETRY_MAX_DELAY)); |
| 16 | |
| 17 | tokio::select! { |
| 18 | _ = sleep(duration) => Ok(()), |
| 19 | _ = cancel.cancelled() => Err(SleepCancelled), |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | pub fn delay(attempt: u32, error: Option<&ApiErrorInfo>) -> u64 { |
| 24 | if let Some(err) = error { |