Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda