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

118
Vistas
How to break while loop either with timeout or condition is fullfiled?

I want to create a while loop where it will break, whenever timeout finish or condition is fulfilled

async checkFile (filePath) {
    const readDir =  fs.readdirSync(filePath,'utf-8')
    while(true) {
        if(readDir === filename) {
            break;
        }
        
    } 
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

How about something like this? Creating a start date var, then having the condition to loop be that the current date - the start date is less than 1000 (ms) or whatever timeout you would prefer

async checkFile(filePath) {
    const readDir =  fs.readdirSync(filePath,'utf-8');
    const start = new Date();
    while ((new Date()) - start < 1000) {
        if(readDir === filename) {
            break;
        }

    }
}

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