mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 06:51:01 +01:00
Apply suggestions from code review #1002
Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
This commit is contained in:
parent
927e0ad044
commit
58f8a35825
3 changed files with 6 additions and 6 deletions
|
@ -51,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Greatly improved the speed of graceful shutdown (`^C`) ([PR 938](https://github.com/teloxide/teloxide/pull/938))
|
- Greatly improved the speed of graceful shutdown (`^C`) ([PR 938](https://github.com/teloxide/teloxide/pull/938))
|
||||||
- Fix typos in docstrings ([PR 953](https://github.com/teloxide/teloxide/pull/953))
|
- Fix typos in docstrings ([PR 953](https://github.com/teloxide/teloxide/pull/953))
|
||||||
- Use `Seconds` instead of `String` in `InlineQueryResultAudio` for `audio_duration` ([PR 994](https://github.com/teloxide/teloxide/pull/994))
|
- Use `Seconds` instead of `String` in `InlineQueryResultAudio` for `audio_duration` ([PR 994](https://github.com/teloxide/teloxide/pull/994))
|
||||||
- Issue [#780](https://github.com/teloxide/teloxide/issues/780) ([PR 1002](https://github.com/teloxide/teloxide/pull/1002))
|
- High CPU usage on network errors ([PR 1002](https://github.com/teloxide/teloxide/pull/1002), [Issue 780](https://github.com/teloxide/teloxide/issues/780))
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub type BackoffStrategy = Box<dyn Fn(u32) -> Duration + Send>;
|
pub type BackoffStrategy = Box<dyn Send + Fn(u32) -> Duration>;
|
||||||
|
|
||||||
/// Calculates the backoff time in seconds for exponential strategy with base 2
|
/// Calculates the backoff time in seconds for exponential strategy with base 2
|
||||||
///
|
///
|
||||||
/// More at: <https://en.wikipedia.org/wiki/Exponential_backoff#Exponential_backoff_algorithm>
|
/// More at: <https://en.wikipedia.org/wiki/Exponential_backoff#Exponential_backoff_algorithm>
|
||||||
pub fn exponential_backoff_strategy(error_count: u32) -> Duration {
|
pub fn exponential_backoff_strategy(error_count: u32) -> Duration {
|
||||||
Duration::from_secs(2_u64.pow(error_count))
|
Duration::from_secs((1_u64 << error_count).min(30 * 60))
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,9 +88,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The backoff strategy that will be used for delay calculation between
|
/// The backoff strategy that will be used for delay calculation between
|
||||||
/// reconnections
|
/// reconnections caused by network errors.
|
||||||
///
|
///
|
||||||
/// By default, the [`exponential_backoff_strategy`] is used
|
/// By default, the [`exponential_backoff_strategy`] is used.
|
||||||
pub fn backoff_strategy(self, backoff_strategy: BackoffStrategy) -> Self {
|
pub fn backoff_strategy(self, backoff_strategy: BackoffStrategy) -> Self {
|
||||||
Self { backoff_strategy, ..self }
|
Self { backoff_strategy, ..self }
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ impl<B: Requester> Stream for PollingStream<'_, B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Poll eepy future until completion, needed for backoff strategy
|
// Poll eepy future until completion, needed for backoff strategy
|
||||||
if let Some(eepy) = this.eepy.as_mut().as_pin_mut() {
|
else if let Some(eepy) = this.eepy.as_mut().as_pin_mut() {
|
||||||
match eepy.poll(cx) {
|
match eepy.poll(cx) {
|
||||||
Poll::Ready(_) => {
|
Poll::Ready(_) => {
|
||||||
// As soon as delay is waited we increment the counter
|
// As soon as delay is waited we increment the counter
|
||||||
|
|
Loading…
Reference in a new issue