simplify client destruction

This commit is contained in:
Amish Shah
2016-10-26 19:52:41 +01:00
parent 5e2ee2398e
commit 00fe45f6b3
2 changed files with 9 additions and 11 deletions

View File

@@ -234,7 +234,6 @@ class Client extends EventEmitter {
* @returns {Promise} * @returns {Promise}
*/ */
destroy() { destroy() {
return new Promise((resolve, reject) => {
for (const t of this._timeouts) clearTimeout(t); for (const t of this._timeouts) clearTimeout(t);
for (const i of this._intervals) clearInterval(i); for (const i of this._intervals) clearInterval(i);
this._timeouts = []; this._timeouts = [];
@@ -242,8 +241,7 @@ class Client extends EventEmitter {
this.token = null; this.token = null;
this.email = null; this.email = null;
this.password = null; this.password = null;
this.manager.destroy().then(resolve).catch(reject); return this.manager.destroy();
});
} }
/** /**

View File

@@ -59,10 +59,10 @@ class ClientManager {
destroy() { destroy() {
return new Promise((resolve) => { return new Promise((resolve) => {
this.client.ws.destroy();
if (!this.client.user.bot) { if (!this.client.user.bot) {
this.client.rest.methods.logout().then(resolve); this.client.rest.methods.logout().then(resolve);
} else { } else {
this.client.ws.destroy();
resolve(); resolve();
} }
}); });