From aa98a71371d6080a9c9d6691e47d2dd60d47c2ad Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 27 Apr 2025 01:30:01 -0700 Subject: [PATCH] Refactor to simplify for language server The TypeScript language server is not yet capable of understanding that the nullish coalescing assignment will make the property non-null, so it will show a type error. Another workaround would be to assert the property is non-null using a JSDoc equivalent to TypeScript's `!` but that is also not yet supported by JSDoc. --- src/errorStrategies.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/errorStrategies.js b/src/errorStrategies.js index 90a73bc..1ea44da 100644 --- a/src/errorStrategies.js +++ b/src/errorStrategies.js @@ -60,10 +60,10 @@ function placeholder(value) { * @throws If `value` is unset and the function throws an error after the final iteration, the error is re-thrown. */ function retry(iterations, options = {}) { - options.interval ??= 0; + const interval = options.interval ?? 0; return async (row, e, fn) => { while (iterations--) { - await utils.sleep(options.interval); + await utils.sleep(interval); try { return await fn(row); } catch { } } @@ -94,10 +94,10 @@ function retry(iterations, options = {}) { * @throws If `value` is unset and the function throws an error after the final iteration, the error is re-thrown. */ function backoff(iterations, options = {}) { - options.maxExponent ??= Infinity; + const maxExponent = options.maxExponent ?? Infinity; return async (row, e, fn) => { for (let n = 0; n < iterations; n++) { - const exponent = n > options.maxExponent ? options.maxExponent : n; + const exponent = n > maxExponent ? maxExponent : n; const duration = (2 ** exponent) * 1000; // 1s, 2s, 4s, 8s, 16s, ... const jitter = Math.random() * 1000; await utils.sleep(duration + jitter); -- 2.47.3