Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

363
Visualizações
¿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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda