'Making multiple async call in a row from anonymous async function
const loadJSON = () => Promise(
async () => {
const req = await fetch(`data.json`);
return req.json();
}
);
const loadData = (city) => Promise.all(
city.map(async (f) => {
const req = await fetch(`${f}/geo.json`);
return req.json();
})
);
(async () => {
const loadedJSON = await loadJSON();
console.log(loadedJSON);
const loadedData = loadedJSON.map(f => f.loc);
console.log(loadedData);
})();
data.json just contain an array of cities (like London, Barcelona etc). With the second function I want to get the cities locations (cities location are at the city_name/geo.json file)
If I only use the loadJSON and the appropriate parts of the anonymous async function, I am getting the following error message:
Uncaught (in promise) TypeError: undefined is not a promise
at Promise (<anonymous>)
at loadJSON
What is the problem with my code?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
