javascript - Node.js readdir callback called twice -


there have been @ least 2 posts here in past:

nodejs readdir() function being run twice

readfile() callback called twice

both have answers effect readdir called twice, no mystery. case different, illustrated code:

console.log('calling readdir'); fs.readdir(folder,     function (err, files) {         console.log('readdir callback');         // ... deal files     } ); 

which results in output:

calling readdir readdir callback readdir callback 

this not happen folders. workaround, set flag:

let wascalled; ... wascalled = false; console.log('calling readdir'); fs.readdir(folder,     function (err, files) {         if (!wascalled) {             console.log('readdir callback');             wascalled = true;             // ... deal files         }     } ); 

which avoids processing in second call:

calling readdir readdir callback 

i can't see i'm doing wrong, since logging indicates in first case there 2 callbacks single call readdir. perhaps else has encountered , figured out other bug in readdir?

this in renderer process in electron 1.3.3 node.js 6.3.0.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -