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

370
Vistas
¿Es posible hacer que await + setTimeout + for loop funcionen juntos?

Utilizo async y for loop para probar problemas de recuperación que pueden ser causados por la red u otros problemas. pero probar con demasiada frecuencia genera un error de solicitud similar a los pings interminables. Después de regresar, quiero esperar 3000 milisegundos antes de reiniciar la prueba. Este es mi código:

 const fetchtest = async (url, opts, tries=FETCHTEST_LOOP) => { const sleep = m => new Promise(r => setTimeout(r, m)); const errs = []; for (let i = 0; i < tries; i++) { try { return await fetch(url, opts).then(sleep(3000)) ; // << When returned, wait 3000 ms to restart the test. } catch (err) { errs.push(err); } } throw errs; };

este es mi registro:

 𓊈2𓊉 369 update at actiVity trying GET [1 of 10] trying GET [2 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [2 of 10] trying GET [4 of 10] trying GET [3 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [3 of 10] trying GET [1 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [2 of 10] trying GET [4 of 10] trying GET [3 of 10] trying GET [1 of 10] trying GET [2 of 10] trying GET [2 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [3 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [4 of 10] trying GET [2 of 10] trying GET [1 of 10] trying GET [2 of 10] trying GET [1 of 10] 𓊈2𓊉 370 update at actiVity trying GET [1 of 10] trying GET [2 of 10] 𓊈2𓊉 370 update at actiVity 𓊈2𓊉 370 update at actiVity

Soy nuevo en esto.

Tengo una respuesta para esto. cambio a @vercel/fetch API, hace que no necesite usar setTimeout.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No sé exactamente lo que estás intentando, pero tal vez pueda darte una idea.

 const fetchtest = async (url, opts, tries=FETCHTEST_LOOP) => { const errs = []; for (let i = 0; i < tries;) { try { const response = await fetch(url, opts); const data = response.json() if (data){ setTimeout(()=>{i++},3000) } } catch (err) { errs.push(err); setTimeout(()=>{i++},3000) } } throw errs; };

no es súper elegante pero al menos espera 3 segundos antes de reiniciar el ciclo.

Nuevamente, no está claro qué es exactamente lo que quiere (me refiero al propósito de toda su tarea/prueba) y posiblemente haya una mejor manera de lograrlo.

about 4 years ago · Juan Pablo Isaza Denunciar
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