async function tempfunc2(result) {
return new Promise((resolve, reject) => {
for(var i = 0; i < result.length; i++)
{
var url = "SomeURLGeneratedByPreviousFunction";
$.getJSON(url, function(data) {
if (data.mappings["0"]) {
gameHashes.push(data.mappings["0"].game);
}
});
}
return resolve(gameHashes);
});
}
I have this code block that is getting and populating data. Its handling quite a bit of data, so it takes some time.
What I want is for this function to complete before finishing because the next lines of code rely on the result of this function.
However, the way its currently built, it will return the Hashes before the function is complete. How do I await this jQuery function?
I tried putting a .then()
after the $.getJSON
, but it didn't change much.
I also tried putting this particular piece in a different function to try and await it, but that did not work either
await tempfunc().then(tempfunc2);
This is what calls tempfunc2
.