You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
606 B
26 lines
606 B
class UploadTimer {
|
|
/**
|
|
* @constructor
|
|
* @param {number} timeout - timer timeout in msecs.
|
|
* @param {Function} callback - callback to run when timeout reached.
|
|
*/
|
|
constructor(timeout = 0, callback = () => {}) {
|
|
this.timeout = timeout;
|
|
this.callback = callback;
|
|
this.timer = null;
|
|
}
|
|
|
|
clear() {
|
|
clearTimeout(this.timer);
|
|
}
|
|
|
|
set() {
|
|
// Do not start a timer if zero timeout or it hasn't been set.
|
|
if (!this.timeout) return false;
|
|
this.clear();
|
|
this.timer = setTimeout(this.callback, this.timeout);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
module.exports = UploadTimer;
|
|
|