Fix massive timeout/interval memory leaks

This commit is contained in:
Schuyler Cebulskie
2016-09-19 03:49:42 -04:00
parent 6f7deba4b3
commit 7d8667694d
5 changed files with 41 additions and 28 deletions

View File

@@ -31,12 +31,15 @@ class ClientManager {
*/
this.client.emit(Constants.Events.DEBUG, `Authenticated using token ${token}`);
this.client.token = token;
const timeout = this.client.setTimeout(() => reject(new Error(Constants.Errors.TOOK_TOO_LONG)), 1000 * 300);
this.client.rest.methods.getGateway().then(gateway => {
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
this.client.ws.connect(gateway);
this.client.once(Constants.Events.READY, () => resolve(token));
this.client.once(Constants.Events.READY, () => {
resolve(token);
this.client.clearTimeout(timeout);
});
}).catch(reject);
this.client.setTimeout(() => reject(new Error(Constants.Errors.TOOK_TOO_LONG)), 1000 * 300);
}
/**