The fs.stat calls are done concurrently which you can verify with:
var id = 0;
function onlyDirs(file) {
var d = id++;
return fs.statAsync(file).then(function(file) {
console.log("returned from stat call %d", d);
return !file.isFile();
});
}
returned from stat call 0
returned from stat call 1
returned from stat call 2
returned from stat call 3
returned from stat call 5
returned from stat call 4
returned from stat call 6
returned from stat call 7
returned from stat call 8
returned from stat call 10
returned from stat call 11
returned from stat call 14
returned from stat call 13
returned from stat call 9
returned from stat call 15
returned from stat call 18
returned from stat call 17
returned from stat call 16
returned from stat call 12
Note the code didn't work originally, I had to modify this:
var Path = require("path");
function toFullPath(file) {
return Path.join(path, file);
}