ixfx
    Preparing search index...

    Function retryTask

    • Keeps calling a 'probe' function until it returns success. If you just want to call a function until it returns a value, use retryFunction instead.

      const task = {
      probe:(attempts) => {
      // attempts is number of times it has been retried
      if (Math.random() > 0.5) {
      // Return a succesful result
      return { success: true }
      } else {
      return { success: false }
      }
      }

      // Run with retry
      const t = await retryTask(task, opts);

      // Handle result
      if (t.success) {
      // Use the value:
      console.log(t.value);
      } else {
      // Handle failure case
      console.log(t.message);
      }

      What you get back is a RetryResult object, which includes: success: true if task succeeded, false if it failed or was aborted attempts: number of times task was attempted elapsed: milliseconds elapsed since initial call to retryTask value: value returned by task, fallback value if it failed, or undefined. message: message describing outcome. If retry was aborted, message will be abort reason.

      Type Parameters

      • V

      Parameters

      Returns Promise<RetryResult<V>>