title: Future.wait() can't wait without a fiber (while waiting on another future in Meteor.method)
body: <p>In <code>Meteor</code>, I'm writing a method that will have to check a certain path's subdirectories for new files.
  I first would like to just list the subdirectories within <code>Meteor</code> after which I <code>child_process.exec</code> a simple bash script that lists files added since the last time it executed.</p>
  
  <p>I'm having some issues getting the directory discovery to be async (<code>Error: Can't wait without a fiber</code>). I've written a synchronous version but having both <code>fs.readdir</code> and <code>fs.stat</code> in stead of their synchronous alternatives allows me to catch errors.</p>
  
  <p>Here's the code:</p>
  
  <pre><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 &amp;&amp; file.charAt(0) !== '.')
                          resolve2(err, file);
  
                  });
  
                  return future2;
  
              });
  
              Future.wait(dirs);
  
              //var result = _.invoke(dirs, 'get');
  
              future1['return'](_.compact(dirs));
          });
  
          return future1.wait();
      }
  </code></pre>
  
  <p>The error <code>Error: Can't wait without a fiber</code> has to do with <code>future2</code>.
  When I comment out <code>Future.wait(dirs)</code> the server doesn't crash anymore, but that's about as far as I got in trying to solve this. :/</p>
  
  <p>Another <code>_.map</code> function I use in another part of the method works fine with futures. (see also <a href="https://gist.github.com/possibilities/3443021">https://gist.github.com/possibilities/3443021</a> where I found my inspiration)</p>