我有一个独特的情况,其中两个 Promise 在 Promise.all 中一起运行。但其中一个承诺需要很长时间,因此我没有得到任何结果。除了一个,其他承诺正在得到解决。我想用错误消息拒绝需要很长时间(例如:如果超过 60 秒)的承诺,以便我可以从 Promise.all 获得响应。
例如::
const [client1Prices, client2Prices] = await Promise.all([
this.client1.getSimulationPrices({
hourPay: journey.hourPay,
jobType: journey.jobType,
salary: journey.salary,
weeklyHours: journey.weeklyHours,
}),
this.client2.getSimulationPrices({ // takes more than 60 sec and i want to reject this promise
hourPay: journey.hourPay,
jobType: journey.jobType,
salary: journey.salary,
weeklyHours: journey.weeklyHours,
})
]);
this.client2.getSimulationPrices 需要花费大量时间来解决,因此 Promise.all 没有给我任何结果。我想在 60 秒内拒绝这个,这样我就可以得到 Promise.all 的响应。
请建议如何处理这种情况?