From c1b6fc2a976f09331cfd4a34f78419d7f08fe6b1 Mon Sep 17 00:00:00 2001 From: Oj Date: Mon, 4 Apr 2022 15:25:18 +0100 Subject: [PATCH] [Utils > Backoff] Remove as no longer used --- src/utils/Backoff.js | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/utils/Backoff.js diff --git a/src/utils/Backoff.js b/src/utils/Backoff.js deleted file mode 100644 index f81087f..0000000 --- a/src/utils/Backoff.js +++ /dev/null @@ -1,41 +0,0 @@ -module.exports = class Backoff { // Internal library / utility for a class to retry a callback with delays, etc. - constructor(min = 500, max = (min * 10)) { - Object.assign(this, { min, max }); - this.reset(); - - this.pending = () => this._timeoutId != null; // If timeout currently set / waiting - } - - fail(callback) { // On fail, wait and callback - this.current = Math.min(this.current + (this.current * 2), this.max); - - this.fails++; // Bump fails - - if (!callback) return this.current; // No callback given, skip rest of this - if (this._timeoutId != null) throw new Error(); // Timeout already set as waiting for another callback to call, throw error - - this._timeoutId = setTimeout(() => { // Set new timeout - try { - callback(); // Run callback - } finally { - this._timeoutId = null; // Stop tracking timeout internally as it's been executed - } - }, this.current); - - return this.current; - } - - succeed() { // Reset and cancel - this.reset(); - this.cancel(); - } - - cancel() { // Cancel current timeout - this._timeoutId = clearTimeout(this._timeoutId); // Stop timeout - } - - reset() { // Reset internal state - this.current = this.min; - this.fails = 0; - } -}; \ No newline at end of file