Похожие чаты

The vue component has 2 async functions to fetch

data look like this
async getName() {
let res = await fetch(xxx)
res = await res.json()}
return res;}
async getAddr(){
let res = await fetch(xxx)
res = await res.json()}
return res
}
In vuejs component
async mounted (){
this.showLoader=true
let res = await Promise.all([getName(),getAddr()]
//remove loader if response array has been resolved successfully
this.showLoader=false
The problem is here, how do I add a timeout handler for promise.all()?
If over 10 seconds then I would remove the loader component and pop out failed connection notifications ?
Where the handler should be added?

2 ответов

4 просмотра

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race Maybe this is something you can use?

if the timeout is by solid design, promise.race() as suggested by @molteber would work. but if you need to catch failed network connection, use try catch block.

Похожие вопросы

Обсуждают сегодня

For managing user-generated content rights in gaming? 🤯🚀
Brian
37
Do we have a Chinese community here?
迪迦
20
@Aiwan что такое база образца?
Alexey
27
Why binance delisting the token?
🅰🅽🅳🆁🅴🆆
14
Не многие знают, а кто знает, тот уже успел забыть, что в далёком 2004 году эта игра произвела настоящий фурор, настолько революционной была технология, применяемая для её соз...
ICCID
4
Короче я тут узнал полный пиздец Что кучу постов которые я создавал через posted Спустя время не могу редактировать и менять Мол телега возвращае ошибку Это реально так ...
inc.
13
Hi is Atomic wallet safe to exchange btc to xmr?
Regex
20
коллеги, добрый вечер! А никто не знает как модальная форма может себя закрыть? Ну допустим модальная форма определила, что смысла ей работать нет и хочет вернуть modalResult...
Михаил
83
I have LUSD tokens but they haven't pegged back to a dollar. Is there a reason why?
Harry the Hexican
14
Is UniBright Freequity an active live product ? A friend here in Asia was discussing the Tokenisation of RWA’s in his case Real Estate as he’s a developer with numerous overs...
Digital Trust
5
Карта сайта