vercel / async-retry

Retrying made simple, easy and async

Home Page:https://npmjs.com/async-retry

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing function as argument does not work

tvld opened this issue · comments

commented

This is most likely because I am not familiar enough with promises... but, how can I pass a function in a variable and then retry it if it fails the first time?:

// works ok:
await retry(
  async (bail) => {
    const res = await fetch('https://google.com')
  }
);

// does not work 
const Fn = fetch('https://google.com')

await retry(
  async (bail) => {
    const res = await Fn; // if fails first time, it is not called again
  }
);
commented

Answering my own question, this will work:

const Fn =  async () => {
     return await fetch('https://google.com')
 }
      
const res = await retry(
   Fn
)