1

What if I have a recursive function like below? Can I just return false after the recursive foo call?

function foo(fn, redo, interval = 1000) {
  return new Promise(
    (resolve, reject) => {
      fn()
        .then(resolve)
        .catch((error) => {
          setTimeout(() => {
            if (redo === 1) {
              reject(error);
              const unusedComponent = () => null;
              return unusedComponent;
            }

            foo(fn, retriesLeft - 1, interval).then(resolve, reject);
          }, interval);
          return null;
        });
    }
  );
}
stackjlei
  • 9,485
  • 18
  • 65
  • 113
  • 1
    Is something about this not working? This code looks like it should work already, although it could be cleaned up and shortened significantly. The return value from a function given to `setTimeout` will be discarded so it doesn't matter what you return after the recursive `foo` call, so returning `false` or not returning at all will give the same result. – CRice Jun 23 '20 at 23:11
  • it was still erroring with prettier, so i wanted a way around it. I found it by returning the recursive call – stackjlei Jun 23 '20 at 23:56

1 Answers1

0

Return recursive call by adding in return on the foo

stackjlei
  • 9,485
  • 18
  • 65
  • 113