This code snippet is taken from google developers:
// map some URLs to json-promises
const jsonPromises = urls.map(async url => {
const response = await fetch(url);
return response.json();
});
I understand that at the end jsonPromises
is going to be an array of Promises. However, i'm not completely sure how that happens.
According to my understanding, when execution gets to this line const response = await fetch(url);
it moves it from call stack to Web Api, does the same to return response.json();
and moves to the next url
from urls
. Is it correct ? I understand how event loop works when it comes to simple setTimeout
, but this example confuses me a lot.