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;
}
}
}
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;
}
}
}