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

209
Views
¿Cómo hacer que una función espere hasta que sus instancias recursivas también se completen? - JavaScript

Tengo dos funciones en JS, una llama a otra, pero la primera vuelve a intentarlo después de un segundo si una condición se vuelve falsa. El problema es que quiero que la segunda función espere hasta que también se completen estas instancias recursivas.

Esto es lo que tengo hasta ahora:

 async function firstFunction(){ if(SomeCondition){ //do something } else{ //do something setTimeout(() => { firstFunction(); }, 1000); //Tries again in 1 second } } async function secondFunction(){ await firstFunction() //waiting firstFunction and its instances to finish }

No se me ocurre cómo solucionar esto, ¿alguna idea?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ya que ha hecho firstFunction async , use Promises para hacer lo que necesita

 async function firstFunction() { if (SomeCondition) { //do something } else { //do something await new Promise(r => setTimeout(r, 1000)) await firstFunction(); } } async function secondFunction() { await firstFunction() //waiting firstFunction and its instances to finish }
about 4 years ago · Juan Pablo Isaza Report
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!