首页 > 解决方案 > 如何一次取消所有正在进行的 Promise

问题描述

Promise想象一个通过该函数发出数百个请求 () 的工具:

function send(requestPromise, successFn, failureFn) {
  incrementCounters();
  requestPromise()
    .then(response => successFn(response.headers, response.data))
    .catch(() => failureFn())
    .finally(() => decrementCounters());
}

现在,假设被联系的服务器决定拒绝所有后续请求,因为客户端点击了API-Rate Limit.

假设客户端想要停止等待所有请求:客户端如何让所有正在进行的 Promise 失败?

因此,约束是:

标签: javascriptpromisees6-promise

解决方案


推荐阅读