Fix requests getting locked up in queues

This commit is contained in:
Amish Shah
2016-08-22 19:15:08 +01:00
parent 89569d9249
commit df456589ab
4 changed files with 19 additions and 19 deletions

View File

@@ -39,7 +39,7 @@ class RESTManager {
if (!this.handlers[apiRequest.getEndpoint()]) {
const RequestHandlerType = this.getRequestHandler();
this.handlers[apiRequest.getEndpoint()] = new RequestHandlerType(this);
this.handlers[apiRequest.getEndpoint()] = new RequestHandlerType(this, apiRequest.getEndpoint());
}
return this.push(this.handlers[apiRequest.getEndpoint()], apiRequest);

View File

@@ -9,8 +9,8 @@ const RequestHandler = require('./RequestHandler');
*/
class SequentialRequestHandler extends RequestHandler {
constructor(restManager) {
super(restManager);
constructor(restManager, endpoint) {
super(restManager, endpoint);
/**
* Whether this rate limiter is waiting for a response from a request
@@ -18,6 +18,12 @@ class SequentialRequestHandler extends RequestHandler {
*/
this.waiting = false;
/**
* The endpoint that this handler is handling
* @type {String}
*/
this.endpoint = endpoint;
/**
* The time difference between Discord's Dates and the local computer's Dates. A positive number means the local
* computer's time is ahead of Discord's.
@@ -51,7 +57,7 @@ class SequentialRequestHandler extends RequestHandler {
this.waiting = false;
this.globalLimit = false;
resolve();
}, res.headers['retry-after'] + 500);
}, Number(res.headers['retry-after']) + 500);
if (res.headers['x-ratelimit-global']) {
this.globalLimit = true;
}