Похожие чаты

I am getting confused on how async-await function does not

block operation

let say I have a function named foo,I want to make the statement console.log('done') can execute without wating for resolving fetch response.
function foo(){
console.log('hello world'); //1
var res = fetch.get(); //ajax //2
console.log('done'); //3
}
execution order: 1,2,3
In promised-based solution,I can do something like this
function foo(){

console.log('hello world'); //1
fetch.get().then((result)=>{
var res = result;
}); //ajax 2
console.log('done'); //3

}
so that the execution order would be 1,3,2

However, Once changed this in async-await pattern

async function foo(){

console.log('hello world'); //1
var res = await fetch.get(); //ajax 2
console.log('done'); //3

}

the console.log('done') executed only the response has received.

exeuction order: 1 2 3

How do I make it non-blocking?

2 ответов

6 просмотров

if on node, use Node version 8. there is a feature bug which causes the engine to behave as you expect.

console.log('hello world'); const p = fetch.get(); console.log('done'); await p;

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

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

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
Карта сайта