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

151
Views
Obtener valor de setTimout dentro de un forEach

Ahora he pasado varias horas aquí leyendo las soluciones a este problema, así: Obtener el valor de retorno de setTimeout

Pero no puedo encontrar ninguna solución para mi problema para obtener el valor removeCount. También traté de agregar una Promesa, pero no sé cómo hacerlo con el incremento.

 async function removeNeedlessNotifications(mutations) { const getResult = async () => { let removeCount = 0; mutations.forEach((v) => v.addedNodes.forEach((v, i) => setTimeout(() => { if (notificationFilter(v)) { v.querySelector("div.activity-remove.js-remove").click(); removeCount++; } }, i * 100) ) ); return removeCount; }; return await getResult(); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use dos bucles for en su lugar para que pueda await adentro, y se vuelve trivial:

 async function removeNeedlessNotifications(mutations) { let removeCount = 0; for (const mutation of mutations) { for (const node of mutation.addedNodes) { await new Promise(r => setTimeout(r, 100)); if (notificationFilter(node)) { node.querySelector("div.activity-remove.js-remove").click(); removeCount++; } } } return removeCount; }

Esto devolverá una Promesa que se resuelve en la cantidad de divs en los que se hizo clic.

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!