I'm a bit confused about promises in javascript and the resolve() statement. I have this code
this.fetchRuns("https://www.speedrun.com/api/v1/runs?game=" + game_id).
then(() => console.log("abc"));
fetchRuns(url, max);
{
return new Promise((resolve, reject) => {
if (this.runs.length >= 100) return resolve();
fetch(url)
.then((data) => data.json())
.then((json_obj) => {
json_obj["data"].forEach((element) => {
this.runs.push(element);
});
if (json_obj["pagination"]["links"].length == 0) return resolve();
else {
if (json_obj["pagination"]["links"].length == 1)
resolve(this.fetchRuns(json_obj["pagination"]["links"][0]["uri"]));
else resolve(this.fetchRuns(json_obj["pagination"]["links"][1]["uri"]));
}
});
});
}
When I recursively call the function again, I need to use resolve() so that console.log("abc") gets called. I want to know the reason why.
My own thought is that every promise needs to be resolved so that then() will be called and when I don't use resolve() in the recursive call then the promise doesn't get resolved. Am I right with that?