aboutsummaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-07-04 13:52:33 -0700
committerZeyla Hellyer <[email protected]>2018-07-04 13:54:21 -0700
commit55555b88dd44366e27d2c7cc02166995a3835a69 (patch)
tree59d707146dfe4c72a0d5b90c770d3e9c4c0f7130 /src/http
parentproperly fix the is_nsfw check this time (diff)
downloadserenity-55555b88dd44366e27d2c7cc02166995a3835a69.tar.xz
serenity-55555b88dd44366e27d2c7cc02166995a3835a69.zip
Add http::ratelimiting::offset
Add a function to access a copy of the ratelimiting module's internal `OFFSET` static binding.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/ratelimiting.rs36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/http/ratelimiting.rs b/src/http/ratelimiting.rs
index e9008b4..b8152d1 100644
--- a/src/http/ratelimiting.rs
+++ b/src/http/ratelimiting.rs
@@ -56,20 +56,9 @@ use std::{
};
use super::{HttpError, LightMethod};
-/// The calculated offset of the time difference between Discord and the client
-/// in seconds.
-///
-/// This does not have millisecond precision as calculating that isn't
-/// realistic.
+/// Refer to [`offset`].
///
-/// This is used in ratelimiting to help determine how long to wait for
-/// pre-emptive ratelimits. For example, if the client is 2 seconds ahead, then
-/// the client would think the ratelimit is over 2 seconds before it actually is
-/// and would then send off queued requests. Using an offset, we can know that
-/// there's actually still 2 seconds left (+/- some milliseconds).
-///
-/// This isn't a definitive solution to fix all problems, but it can help with
-/// some precision gains.
+/// [`offset`]: fn.offset.html
static mut OFFSET: Option<i64> = None;
lazy_static! {
@@ -540,6 +529,27 @@ impl RateLimit {
}
}
+/// The calculated offset of the time difference between Discord and the client
+/// in seconds.
+///
+/// This does not have millisecond precision as calculating that isn't
+/// realistic.
+///
+/// This is used in ratelimiting to help determine how long to wait for
+/// pre-emptive ratelimits. For example, if the client is 2 seconds ahead, then
+/// the client would think the ratelimit is over 2 seconds before it actually is
+/// and would then send off queued requests. Using an offset, we can know that
+/// there's actually still 2 seconds left (+/- some milliseconds).
+///
+/// This isn't a definitive solution to fix all problems, but it can help with
+/// some precision gains.
+///
+/// This will return `None` if an HTTP request hasn't been made, meaning that
+/// no offset could have been calculated.
+pub fn offset() -> Option<i64> {
+ unsafe { OFFSET }
+}
+
fn calculate_offset(header: Option<&[Vec<u8>]>) {
// Get the current time as soon as possible.
let now = Utc::now().timestamp();