Лучший способ ожидания более чем одной асинхронной функции до конца sh - это Promise.all
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
Вот пример более современного способа написания сети звонки с использованием fetch:
async function fetchMap([lat, lon]) {
const request = await fetch(
`https://nominatim.openstreetmap.org/reverse.php?zoom=18&format=json&accept-language=si&lat=${lat}&lon=${lon}`
);
return await request.json();
}
async function getMapData(coordinates1, coordinates2, callback) {
const request1 = fetchMap(coordinates1)
const request2 = fetchMap(coordinates2)
const resolvedResponses = await Promise.all([request1, request2]);
callback(...resolvedResponses);
}
// This will get data for Tokyo and New York,
// and wait to call the passed-in function until both sets of JSON data are return.
getMapData([35.6850, 139.7514], [40.6943,-73.9249], console.log);
/* ^ instead of "console.log" put a reference to whichever function you want to call.
It could be an anonymous function such as the one shown in your question. */