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

113
Views
¿Cómo esperar la finalización de todo el proceso de una función llamada por eventos?

Tengo una función que se dispara por un evento, ¿hay alguna forma de esperar a que se complete todo el proceso de esta función, incluso si el evento se dispara otras veces, para que solo después de eso continúe procesando los otros disparadores recibidos?

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

0

Por lo que entendí, necesitas algún tipo de cola. Necesita enviar eventos allí y procesarlos uno por uno. Tal vez algo como esto:

 const queue = []; function eventHandler(event) { queue.push(event); if (queue.length === 1) { doTheJob(); } } async function doTheJob() { if (queue.length > 0) { const event = queue[0] // do the job with the "event" await work1(); await work2(); await workN(); queue.shift(); doTheJob(); } }
about 4 years ago · Juan Pablo Isaza Report

0

Me las arreglé para encontrar una solución como esta:

 var time = 1; // SIMULATES THE ACTIVITIES OF THE EVENT setInterval(async () => { await process(); }, 1000); // THE PROCESSING THAT OCCURS WHEN THE EVENT IS TRIGGERED async function process() { time += 4000 const myPromise = await new Promise(async function (myResolve, myReject) { setTimeout(async () => { console.log(`Process executed`); myResolve("Process completed"); }, time); });//End myPromise var result = await myPromise; time = time - 4000 }

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!