aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-21 14:23:44 -0800
committerAustin Hellyer <[email protected]>2016-11-21 14:23:44 -0800
commitffcdde449de177b5e44079841dd6f86ec726f85c (patch)
treeb248fb9baea80e5cd5d8a21e8e277a1bcca80dc4
parentAdd created_at method to Ids and User (diff)
downloadserenity-ffcdde449de177b5e44079841dd6f86ec726f85c.tar.xz
serenity-ffcdde449de177b5e44079841dd6f86ec726f85c.zip
Don't block entirely on HTTP requests
While this has the potential to hit 429s in very minimal periods of time, this will allow multiple concurrent HTTP requests, whereas before they were forced to be sync.
-rw-r--r--src/client/http/ratelimiting.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/client/http/ratelimiting.rs b/src/client/http/ratelimiting.rs
index 9281563..65af1a3 100644
--- a/src/client/http/ratelimiting.rs
+++ b/src/client/http/ratelimiting.rs
@@ -106,13 +106,6 @@ pub enum Route {
pub fn perform<'a, F>(route: Route, f: F) -> Result<Response>
where F: Fn() -> RequestBuilder<'a> {
- // Keeping the global lock poisoned here for the duration of the function
- // will ensure that requests are synchronous, which will further ensure
- // that 429s are _never_ hit.
- //
- // This would otherwise cause the potential for 429s to be hit while
- // requests are open.
- let mut global = GLOBAL.lock().expect("global route lock poisoned");
loop {
// Perform pre-checking here:
@@ -123,7 +116,10 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response>
// - get the global rate;
// - sleep if there is 0 remaining
// - then, perform the request
- global.pre_hook();
+ {
+ let mut global = GLOBAL.lock().expect("global route lock poisoned");
+ global.pre_hook();
+ }
if route != Route::None {
if let Some(route) = ROUTES.lock().expect("routes poisoned").get_mut(&route) {
@@ -149,6 +145,7 @@ pub fn perform<'a, F>(route: Route, f: F) -> Result<Response>
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)
} else {
ROUTES.lock()