Sleep for `ms` milliseconds, returning early if the `cancel` receiver signals `true`.
(ms: u64, mut cancel: watch::Receiver<bool>)
| 53 | /// Sleep for `ms` milliseconds, returning early if the `cancel` receiver |
| 54 | /// signals `true`. |
| 55 | pub async fn sleep(ms: u64, mut cancel: watch::Receiver<bool>) { |
| 56 | let capped = ms.min(RETRY_MAX_DELAY); |
| 57 | let duration = std::time::Duration::from_millis(capped); |
| 58 | |
| 59 | tokio::select! { |
| 60 | _ = tokio::time::sleep(duration) => {} |
| 61 | _ = async { |
| 62 | while !*cancel.borrow_and_update() { |
| 63 | if cancel.changed().await.is_err() { |
| 64 | // Sender dropped – treat as cancellation. |
| 65 | return; |
| 66 | } |
| 67 | } |
| 68 | } => {} |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // --------------------------------------------------------------------------- |
| 73 | // delay – compute how long to wait before the next retry |
no outgoing calls