mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
Fix sequential rate limiting
This commit is contained in:
@@ -38,7 +38,6 @@ class RESTManager {
|
|||||||
|
|
||||||
makeRequest(method, url, auth, data, file) {
|
makeRequest(method, url, auth, data, file) {
|
||||||
const apiRequest = new APIRequest(this, method, url, auth, data, file);
|
const apiRequest = new APIRequest(this, method, url, auth, data, file);
|
||||||
|
|
||||||
if (!this.handlers[apiRequest.route]) {
|
if (!this.handlers[apiRequest.route]) {
|
||||||
const RequestHandlerType = this.getRequestHandler();
|
const RequestHandlerType = this.getRequestHandler();
|
||||||
this.handlers[apiRequest.route] = new RequestHandlerType(this, apiRequest.route);
|
this.handlers[apiRequest.route] = new RequestHandlerType(this, apiRequest.route);
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ class SequentialRequestHandler extends RequestHandler {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.timeDifference = 0;
|
this.timeDifference = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the queue is being processed or not
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.busy = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
push(request) {
|
push(request) {
|
||||||
@@ -40,6 +46,7 @@ class SequentialRequestHandler extends RequestHandler {
|
|||||||
* @returns {Promise<?Object|Error>}
|
* @returns {Promise<?Object|Error>}
|
||||||
*/
|
*/
|
||||||
execute(item) {
|
execute(item) {
|
||||||
|
this.busy = true;
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
item.request.gen().end((err, res) => {
|
item.request.gen().end((err, res) => {
|
||||||
if (res && res.headers) {
|
if (res && res.headers) {
|
||||||
@@ -82,8 +89,11 @@ class SequentialRequestHandler extends RequestHandler {
|
|||||||
|
|
||||||
handle() {
|
handle() {
|
||||||
super.handle();
|
super.handle();
|
||||||
if (this.remaining === 0 || this.queue.length === 0 || this.globalLimit) return;
|
if (this.busy || this.remaining === 0 || this.queue.length === 0 || this.globalLimit) return;
|
||||||
this.execute(this.queue.shift()).then(() => this.handle());
|
this.execute(this.queue.shift()).then(() => {
|
||||||
|
this.busy = false;
|
||||||
|
this.handle();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user