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

160
Views
llamar a una función por n veces con 2 segundos de retraso

Estoy ejecutando un código donde debo crear una función y llamarla 3 veces con 2 segundos de retraso entre cada una. Tengo problemas para llamarla más de una vez. ¿Cómo puedo resolver esto? Yo uso javascript. Creo myfunc () para iniciar sesión en la consola cada 2 segundos por 3 veces.

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

0

 const myFunc = () => console.log("hello"); const runFunc = async (func, times, delay) => { for (let i = 0; i < times; i++) { func(); if (i + 1 < times) await new Promise(res => setTimeout(res, delay)); } } runFunc(myFunc, 3, 2 * 1000);

o esto

 const myFunc = () => console.log("hello"); const runFunc = async (func, times, delay) => { if (times >= 1) func(); times--; if (times >= 1) { const interval = setInterval(() => { times--; if (times <= 0) clearInterval(interval); func(); }, delay); } } runFunc(myFunc, 3, 2 * 1000);

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!