mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 15:01:45 +01:00
Fix typos & stuff
This commit is contained in:
parent
2477a0f945
commit
c24f7f4fc0
3 changed files with 15 additions and 11 deletions
|
@ -33,15 +33,17 @@ pub use settings::{Limits, Settings};
|
||||||
///
|
///
|
||||||
/// Telegram has strict [limits], which, if exceeded will sooner or later cause
|
/// Telegram has strict [limits], which, if exceeded will sooner or later cause
|
||||||
/// `RequestError::RetryAfter(_)` errors. These errors can cause users of your
|
/// `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
|
/// This bot wrapper automatically checks for limits, suspending requests until
|
||||||
/// they could be sent without exceeding limits (request order in chats is not
|
/// they could be sent without exceeding limits (request order in chats is not
|
||||||
/// changed).
|
/// changed).
|
||||||
///
|
///
|
||||||
/// It's recommended to use this wrapper before other wrappers (i.e.:
|
/// It's recommended to use this wrapper before other wrappers (i.e.:
|
||||||
/// `SomeWrapper<Throttle<Bot>>`) because if done otherwise inner wrappers may
|
/// `SomeWrapper<Throttle<Bot>>` not `Throttle<SomeWrapper<Bot>>`) because if
|
||||||
/// cause `Throttle` to miscalculate limits usage.
|
/// 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
|
/// [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 {
|
match value {
|
||||||
Recipient::Id(id) => ChatIdHash::Id(*id),
|
Recipient::Id(id) => ChatIdHash::Id(*id),
|
||||||
Recipient::ChannelUsername(username) => {
|
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();
|
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||||
username.hash(&mut hasher);
|
username.hash(&mut hasher);
|
||||||
let hash = hasher.finish();
|
let hash = hasher.finish();
|
||||||
|
|
|
@ -145,8 +145,8 @@ where
|
||||||
{
|
{
|
||||||
// We use option in `ShareableRequest` to `take` when sending by value.
|
// We use option in `ShareableRequest` to `take` when sending by value.
|
||||||
//
|
//
|
||||||
// All unwraps down below will succed because we always return immediately after
|
// All unwraps down below will succeed because we always return immediately
|
||||||
// taking.
|
// after taking.
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (lock, wait) = channel();
|
let (lock, wait) = channel();
|
||||||
|
|
|
@ -21,7 +21,7 @@ const SECOND: Duration = Duration::from_secs(1);
|
||||||
// want to change this.
|
// want to change this.
|
||||||
const DELAY: Duration = Duration::from_millis(250);
|
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);
|
const QUEUE_FULL_DELAY: Duration = Duration::from_secs(4);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -126,12 +126,12 @@ pub(super) async fn worker<B>(
|
||||||
while !rx_is_closed || !queue.is_empty() {
|
while !rx_is_closed || !queue.is_empty() {
|
||||||
// FIXME(waffle):
|
// FIXME(waffle):
|
||||||
// 1. If the `queue` is empty, `read_from_rx` call down below will 'block'
|
// 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.
|
// `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);
|
answer_info(&mut info_rx, &mut limits);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -192,7 +192,7 @@ pub(super) async fn worker<B>(
|
||||||
let min_back = now - MINUTE;
|
let min_back = now - MINUTE;
|
||||||
let sec_back = now - SECOND;
|
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() {
|
while let Some((_, time)) = history.front() {
|
||||||
// history is sorted, we found first up-to-date thing
|
// history is sorted, we found first up-to-date thing
|
||||||
if time >= &min_back {
|
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() {
|
while queue.len() < queue.capacity() {
|
||||||
match rx.try_recv() {
|
match rx.try_recv() {
|
||||||
Ok(req) => queue.push(req),
|
Ok(req) => queue.push(req),
|
||||||
|
|
Loading…
Reference in a new issue