I have the following code in node.js
for (var i = 0; i<allLetters.length; i++)
for (var k = 0; k<allLetters.length; k++){
var allFilesName = fs.readdirSync("/opt/ + allLetters[i] + "/" + allLetters[k]);
for (var t = 0; t< akkFilesName; t++)
dosomething(allFilesName[t];
}
dosomething is a function with callback, and include IO operation.
the problem is that my application doesn't executed the callback until it finish the i, k & t loops. Meaning, I see that all the CPU time is wasted on completed the callback, and just after it complete all the loops, it executed the callback, and returns from the callback.
I want that the loops and the callback will executed parallel, so I would get the result from the callback while I do the loop.
As stated in the comments, the each-Function of the async-Library does what you are looking for.