From: Ardis Lu Date: Sun, 27 Apr 2025 08:30:01 +0000 (-0700) Subject: Refactor to simplify for language server X-Git-Tag: v0.1.0~29 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=aa98a71371d6080a9c9d6691e47d2dd60d47c2ad;p=csvio 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. --- 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);