Passing function as argument does not work
tvld opened this issue · 1 comments
tvld 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
}
);
tvld commented
Answering my own question, this will work:
const Fn = async () => {
return await fetch('https://google.com')
}
const res = await retry(
Fn
)