Fix typos & stuff

This commit is contained in:
Maybe Waffle 2022-04-10 19:16:41 +04:00
parent 2477a0f945
commit c24f7f4fc0
3 changed files with 15 additions and 11 deletions

View file

@ -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<Throttle<Bot>>`) because if done otherwise inner wrappers may
/// cause `Throttle` to miscalculate limits usage.
/// `SomeWrapper<Throttle<Bot>>` not `Throttle<SomeWrapper<Bot>>`) 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();

View file

@ -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();

View file

@ -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<B>(
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<B>(
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<T>(rx: &mut mpsc::Receiver<T>, queue: &mut Vec<T>, 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),