mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
Switch timeouts/intervals to Sets
This commit is contained in:
@@ -103,8 +103,8 @@ class Client extends EventEmitter {
|
|||||||
* @type {?Date}
|
* @type {?Date}
|
||||||
*/
|
*/
|
||||||
this.readyTime = null;
|
this.readyTime = null;
|
||||||
this._timeouts = [];
|
this._timeouts = new Set();
|
||||||
this._intervals = [];
|
this._intervals = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,8 +138,8 @@ class Client extends EventEmitter {
|
|||||||
destroy() {
|
destroy() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.manager.destroy().then(() => {
|
this.manager.destroy().then(() => {
|
||||||
for (const i of this._intervals) clearInterval(i);
|
|
||||||
for (const t of this._timeouts) clearTimeout(t);
|
for (const t of this._timeouts) clearTimeout(t);
|
||||||
|
for (const i of this._intervals) clearInterval(i);
|
||||||
this._timeouts = [];
|
this._timeouts = [];
|
||||||
this._intervals = [];
|
this._intervals = [];
|
||||||
this.token = null;
|
this.token = null;
|
||||||
@@ -225,26 +225,26 @@ class Client extends EventEmitter {
|
|||||||
setTimeout(fn, ...params) {
|
setTimeout(fn, ...params) {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
fn();
|
fn();
|
||||||
this._timeouts.splice(this._timeouts.indexOf(timeout), 1);
|
this._timeouts.delete(timeout);
|
||||||
}, ...params);
|
}, ...params);
|
||||||
this._timeouts.push(timeout);
|
this._timeouts.add(timeout);
|
||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearTimeout(timeout) {
|
clearTimeout(timeout) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
this._timeouts.splice(this._timeouts.indexOf(timeout), 1);
|
this._timeouts.delete(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(...params) {
|
setInterval(...params) {
|
||||||
const interval = setInterval(...params);
|
const interval = setInterval(...params);
|
||||||
this._intervals.push(interval);
|
this._intervals.add(interval);
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearInterval(interval) {
|
clearInterval(interval) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
this._intervals.splice(this._intervals.indexOf(interval), 1);
|
this._intervals.delete(interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user