From af75e43900e01fae31c65a2871dd9d4a3c519c0f Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sat, 19 Aug 2017 20:14:49 -0700 Subject: [PATCH] proper fix for #1685 (#1805) * Update WebSocketConnection.js * Update WebSocketConnection.js * Update WebSocketConnection.js * Update RESTManager.js --- src/client/rest/RESTManager.js | 4 ++-- src/client/websocket/WebSocketConnection.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/rest/RESTManager.js b/src/client/rest/RESTManager.js index 37d5a95993e6..d8a0ec78a013 100644 --- a/src/client/rest/RESTManager.js +++ b/src/client/rest/RESTManager.js @@ -16,8 +16,8 @@ class RESTManager { } destroy() { - for (const handlerID in this.handlers) { - this.handlers[handlerID].destroy(); + for (const handler of Object.values(this.handlers)) { + if (handler.destroy) handler.destroy(); } } diff --git a/src/client/websocket/WebSocketConnection.js b/src/client/websocket/WebSocketConnection.js index c0581a208eae..58c7da1d07db 100644 --- a/src/client/websocket/WebSocketConnection.js +++ b/src/client/websocket/WebSocketConnection.js @@ -81,8 +81,8 @@ class WebSocketConnection extends EventEmitter { */ this.ratelimit = { queue: [], - remaining: 120, - resetTime: -1, + remaining: 60, + resetTimer: null, }; this.connect(gateway); @@ -190,10 +190,10 @@ class WebSocketConnection extends EventEmitter { if (this.ratelimit.remaining === 0) return; if (this.ratelimit.queue.length === 0) return; if (this.ratelimit.remaining === 120) { - this.ratelimit.resetTimer = setTimeout(() => { - this.ratelimit.remaining = 120; + this.ratelimit.resetTimer = this.client.setTimeout(() => { + this.ratelimit.remaining = 60; this.processQueue(); - }, 120e3); // eslint-disable-line + }, 120e3); } while (this.ratelimit.remaining > 0) { const item = this.ratelimit.queue.shift();