unliar / unliar.github.io

一个已经不再使用的静态博客,新的博客在后边。
https://happysooner.com
0 stars 0 forks source link

实现一个请求重试函数 #37

Open unliar opened 3 years ago

unliar commented 3 years ago
const retry = async (promise, times = 0) => {
  try {
    return await promise();
  } catch (error) {
     times= times -1;
    if (times>=0) {
      return await retry(promise, times);
    } else {
      throw error;
    }
  }