Erioifpuderio.hashnode.dev·May 29, 2024关于 Promise 的重试这段时间经常用到重试功能,因为一些需求实现起来需要频繁访问接口,但这个接口不是我们自己的,服务器在海外,所以访问起来失败率肉眼可见地高,所以我需要在访问失败(因为连接原因)时自动进行重试。 既然常用,那就把他记下来,方便下次查阅。 实现 先准备一个假的 fetch,在文章里面我不会真去访问这个接口,就拿假 fetch 来当例子: const fetch = (url) => { return new Promise((resolve, reject) => { const r = M...2Articles1WeekAdd a thoughtful commentNo comments yetBe the first to start the conversation.