Document client timeout/interval stuff

This commit is contained in:
Schuyler Cebulskie
2016-10-30 17:02:06 -04:00
parent 85330769a7
commit f2496070d3

View File

@@ -336,26 +336,48 @@ class Client extends EventEmitter {
return this.rest.methods.getMyApplication(); return this.rest.methods.getMyApplication();
} }
setTimeout(fn, ...params) { /**
* Sets a timeout that will be automatically cancelled if the client is destroyed.
* @param {function} fn Function to execute
* @param {number} delay Time to wait before executing (in milliseconds)
* @param {args} args Arguments for the function (not an array, but an infinite argument)
* @returns {Timeout}
*/
setTimeout(fn, delay, ...args) {
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
fn(); fn();
this._timeouts.delete(timeout); this._timeouts.delete(timeout);
}, ...params); }, delay, ...args);
this._timeouts.add(timeout); this._timeouts.add(timeout);
return timeout; return timeout;
} }
/**
* Clears a timeout
* @param {Timeout} timeout Timeout to cancel
*/
clearTimeout(timeout) { clearTimeout(timeout) {
clearTimeout(timeout); clearTimeout(timeout);
this._timeouts.delete(timeout); this._timeouts.delete(timeout);
} }
setInterval(...params) { /**
const interval = setInterval(...params); * Sets an interval that will be automatically cancelled if the client is destroyed.
* @param {function} fn Function to execute
* @param {number} delay Time to wait before executing (in milliseconds)
* @param {args} args Arguments for the function (not an array, but an infinite argument)
* @returns {Timeout}
*/
setInterval(fn, delay, ...args) {
const interval = setInterval(fn, delay, ...args);
this._intervals.add(interval); this._intervals.add(interval);
return interval; return interval;
} }
/**
* Clears an interval
* @param {Timeout} interval Interval to cancel
*/
clearInterval(interval) { clearInterval(interval) {
clearInterval(interval); clearInterval(interval);
this._intervals.delete(interval); this._intervals.delete(interval);