异步等待超时

异步等待超时,第1张

异步/等待超时

您可以使用

Promise.race
超时:

Promise.race([    doSomethingInSeries(),    new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 11.5e3))]).catch(function(err) {    // errors in res1, res2, res3 and the timeout will be caught here})

您必须

setTimeout
将其包装在诺言中才能使用。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5016159.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存