From dc125e3b659b05b803227976bf2db61afe458de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=8B=D1=80=D1=86=D0=B5=D0=B2=20=D0=92=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=20=D0=98=D0=B3=D0=BE=D1=80=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 28 Jul 2024 21:57:41 +0300 Subject: [PATCH] Put incrementing `error count` to the `Err` branch of `PollingStream::poll_next` --- crates/teloxide/src/update_listeners/polling.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/teloxide/src/update_listeners/polling.rs b/crates/teloxide/src/update_listeners/polling.rs index a7a8f010..8209f778 100644 --- a/crates/teloxide/src/update_listeners/polling.rs +++ b/crates/teloxide/src/update_listeners/polling.rs @@ -450,7 +450,12 @@ impl Stream for PollingStream<'_, B> { *this.error_count = 0; seconds.duration() } - None => (this.polling.backoff_strategy)(*this.error_count), + None => { + let delay = (this.polling.backoff_strategy)(*this.error_count); + *this.error_count = this.error_count.saturating_add(1); + log::trace!("current error count: {}", *this.error_count); + delay + } }; log::info!("retrying getting updates in {}s", delay.as_secs()); this.eepy.set(Some(sleep(delay))); @@ -462,9 +467,6 @@ impl Stream for PollingStream<'_, B> { // Poll eepy future until completion, needed for backoff strategy else if let Some(eepy) = this.eepy.as_mut().as_pin_mut() { ready!(eepy.poll(cx)); - // As soon as delay is waited we increment the counter - *this.error_count = this.error_count.saturating_add(1); - log::trace!("current error count: {}", *this.error_count); log::trace!("backoff delay completed"); this.eepy.as_mut().set(None); }