ixfx
    Preparing search index...

    Function resolveWithFallback

    • Resolves a value as per resolve, however If an error is thrown or the resolution results in undefined or NaN, fallbackValue is returned instead.

      null is an allowed return value.

      // Function returns undefined 50% of the time or 0
      const fn = () => {
      if (Math.random() >= 0.5) return; // undefined
      return 0;
      }
      const r = resolveWithFallback(fn, 1);
      const value = r(); // Always 0 or 1

      Type Parameters

      Parameters

      Returns Promise<T>