Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

329
Views
Why do I need to to use resolve() when calling a promise recursively

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!