diff --git a/src/adaptors/throttle.rs b/src/adaptors/throttle.rs index caaef945..ecff0e7a 100644 --- a/src/adaptors/throttle.rs +++ b/src/adaptors/throttle.rs @@ -33,15 +33,17 @@ pub use settings::{Limits, Settings}; /// /// Telegram has strict [limits], which, if exceeded will sooner or later cause /// `RequestError::RetryAfter(_)` errors. These errors can cause users of your -/// bot to never receive responds from the bot or receive them in wrong order. +/// bot to never receive responses from the bot or receive them in a wrong +/// order. /// /// This bot wrapper automatically checks for limits, suspending requests until /// they could be sent without exceeding limits (request order in chats is not /// changed). /// /// It's recommended to use this wrapper before other wrappers (i.e.: -/// `SomeWrapper>`) because if done otherwise inner wrappers may -/// cause `Throttle` to miscalculate limits usage. +/// `SomeWrapper>` not `Throttle>`) because if +/// done otherwise inner wrappers may cause `Throttle` to miscalculate limits +/// usage. /// /// [limits]: https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this /// @@ -209,6 +211,8 @@ impl From<&Recipient> for ChatIdHash { match value { Recipient::Id(id) => ChatIdHash::Id(*id), Recipient::ChannelUsername(username) => { + // FIXME: this could probably use a faster hasher, `DefaultHasher` is known to + // be slow (it's not like we _need_ this to be fast, but still) let mut hasher = std::collections::hash_map::DefaultHasher::new(); username.hash(&mut hasher); let hash = hasher.finish(); diff --git a/src/adaptors/throttle/request.rs b/src/adaptors/throttle/request.rs index c109b178..d2188748 100644 --- a/src/adaptors/throttle/request.rs +++ b/src/adaptors/throttle/request.rs @@ -145,8 +145,8 @@ where { // We use option in `ShareableRequest` to `take` when sending by value. // - // All unwraps down below will succed because we always return immediately after - // taking. + // All unwraps down below will succeed because we always return immediately + // after taking. loop { let (lock, wait) = channel(); diff --git a/src/adaptors/throttle/worker.rs b/src/adaptors/throttle/worker.rs index 4aa57099..bbf58a97 100644 --- a/src/adaptors/throttle/worker.rs +++ b/src/adaptors/throttle/worker.rs @@ -21,7 +21,7 @@ const SECOND: Duration = Duration::from_secs(1); // want to change this. const DELAY: Duration = Duration::from_millis(250); -/// Minimal time beetween calls to queue_full function +/// Minimal time between calls to queue_full function const QUEUE_FULL_DELAY: Duration = Duration::from_secs(4); #[derive(Debug)] @@ -126,12 +126,12 @@ pub(super) async fn worker( while !rx_is_closed || !queue.is_empty() { // FIXME(waffle): // 1. If the `queue` is empty, `read_from_rx` call down below will 'block' - // execution untill a request is sent. While the execution is 'blocked' no + // execution until a request is sent. While the execution is 'blocked' no // `InfoMessage`s could be answered. // - // 2. If limits are descreased, ideally we want to shrink queue. + // 2. If limits are decreased, ideally we want to shrink queue. // - // *blocked in asyncronous way + // *blocked in asynchronous way answer_info(&mut info_rx, &mut limits); loop { @@ -192,7 +192,7 @@ pub(super) async fn worker( let min_back = now - MINUTE; let sec_back = now - SECOND; - // make history and hchats up-to-date + // make history and requests_sent up-to-date while let Some((_, time)) = history.front() { // history is sorted, we found first up-to-date thing if time >= &min_back { @@ -361,7 +361,7 @@ async fn read_from_rx(rx: &mut mpsc::Receiver, queue: &mut Vec, rx_is_c } } - // Don't grow queue bigger than the capacity to limit DOS posibility + // Don't grow queue bigger than the capacity to limit DOS possibility while queue.len() < queue.capacity() { match rx.try_recv() { Ok(req) => queue.push(req),