aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2017-02-05 08:42:38 -0800
committerAustin Hellyer <[email protected]>2017-02-05 08:42:38 -0800
commit55ccaca57051b3fbd47cf7fa288014d9c36f6952 (patch)
tree02124eff5d308bce6dfca7135fdb2f0887492394 /src
parentRemove a stupid claim about the lib in the docs (diff)
downloadserenity-55ccaca57051b3fbd47cf7fa288014d9c36f6952.tar.xz
serenity-55ccaca57051b3fbd47cf7fa288014d9c36f6952.zip
Make GLOBAL ratelimit mutex a unit
Instead of making the GLOBAL ratelimit arc-mutex a RateLimit, make it an empty unit.
Diffstat (limited to 'src')
-rw-r--r--src/client/rest/mod.rs2
-rw-r--r--src/client/rest/ratelimiting.rs14
2 files changed, 12 insertions, 4 deletions
diff --git a/src/client/rest/mod.rs b/src/client/rest/mod.rs
index 639b901..b905921 100644
--- a/src/client/rest/mod.rs
+++ b/src/client/rest/mod.rs
@@ -24,7 +24,7 @@
//! [`Context`]: ../struct.Context.html
//! [model]: ../../model/index.html
-mod ratelimiting;
+pub mod ratelimiting;
use hyper::client::{
Client as HyperClient,
diff --git a/src/client/rest/ratelimiting.rs b/src/client/rest/ratelimiting.rs
index e915fb7..e0f78c9 100644
--- a/src/client/rest/ratelimiting.rs
+++ b/src/client/rest/ratelimiting.rs
@@ -50,7 +50,7 @@ use time;
use ::internal::prelude::*;
lazy_static! {
- static ref GLOBAL: Arc<Mutex<RateLimit>> = Arc::new(Mutex::new(RateLimit::default()));
+ static ref GLOBAL: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
static ref ROUTES: Arc<Mutex<HashMap<Route, RateLimit>>> = Arc::new(Mutex::new(HashMap::default()));
}
@@ -147,8 +147,16 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response>
// header. If the limit was 5 and is now 7, add 2 to the 'remaining'
if route != Route::None {
let redo = if response.headers.get_raw("x-ratelimit-global").is_some() {
- let mut global = GLOBAL.lock().expect("global route lock poisoned");
- global.post_hook(&response)
+ let _ = GLOBAL.lock().expect("global route lock poisoned");
+
+ Ok(if let Some(retry_after) = get_header(&response.headers, "retry-after")? {
+ debug!("Ratelimited: {:?}ms", retry_after);
+ thread::sleep(Duration::from_millis(retry_after as u64));
+
+ true
+ } else {
+ false
+ })
} else {
ROUTES.lock()
.expect("routes poisoned")