]> git.ardis.lu - csvio/commitdiff
Refactor to simplify for language server
authorArdis Lu <ardisglu@gmail.com>
Sun, 27 Apr 2025 08:30:01 +0000 (01:30 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 27 Apr 2025 08:30:01 +0000 (01:30 -0700)
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

index 90a73bcfac06c32f0de70312671cd31f2778ce02..1ea44daa050e996015fa718c1d3c1b80d9d3ebcc 100644 (file)
@@ -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);
This page took 0.037301 seconds and 4 git commands to generate.