mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-11-07 16:44:16 +01:00
27 lines
606 B
JavaScript
27 lines
606 B
JavaScript
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;
|