In Meteor , I am writing a method that will have to check specific path subdirectories for new files. At first, I would like to simply list the subdirectories inside Meteor , after which I child_process.exec is a simple bash script that lists the files added since the last execution.
I am having problems finding the directory in async ( Error: Can't wait without a fiber ). I wrote a synchronous version, but instead of fs.readdir and fs.stat instead of my synchronous alternatives, I managed to catch errors.
Here is the code:
function listDirs(dir, isDir){ var future1 = new Future();fs.readdir(dir, function(err, files){ if (err) throw new Meteor.error(500, "Error listing files", err); var dirs = _.map(files, function(file){ var future2 = new Future(); var resolve2 = future2.resolver(); fs.stat(dir+file, function(err, stats){ if (err) throw new Meteor.error(500, "Error statting files", err); if (stats.isDirectory() == isDir && file.charAt(0) !== '.') resolve2(err, file); }); return future2; }); Future.wait(dirs);
Error Error: Can't wait without a fiber is related to future2 . When I comment on Future.wait(dirs) , the server no longer crashes, but that concerns how I tried to solve this problem.: /
Another _.map function, which I use in another part of the method, works great with futures. (see also https://gist.github.com/possibilities/3443021 , where I found my inspiration)
future meteor
jeroentbt
source share