Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript
547 B
Raw Blame
export default function retry (fnPromise, retries = 3) {
  return new Promise((resolve, reject) => {
    const attempt = (n) => {
      fnPromise()
        .then(resolve)
        .catch(async (error) => {
          if (n === 1) {
            console.error('All attempts failed', error)
            reject(error)
          } else {
            console.log(`Retrying... (${n - 1} attempts left)`)
            await new Promise(resolve => setTimeout(resolve, 3000))
            attempt(n - 1)
          }
        })
    }
    attempt(retries)
  })
}