tj/co-fs

fs.exists returns a function

Closed this issue · 2 comments

With this code

var cofsTest = function * () {

  console.log("Unknown file", yield fs.exists('random.file'));
  console.log("this file", yield * fs.exists(__filename));

  return true;
};
var generator = cofsTest();
var genResult;

while (!(genResult = generator.next(genResult && genResult.value)).done);
console.log("Test", genResult.value);

I get this result

Unknown file function (done){
    fs.stat(path, function(err, res){
      done(null, !err);
    });
  }
this file function (done){
    fs.stat(path, function(err, res){
      done(null, !err);
    });
  }
Test true

Where I would have expected something like

Unknown file false
this file true
Test true

The above example returns similar results for every co-fs functions.... were these supposed to be used inside co only?

Disregard this issue. I misunderstood the purpose of this module and thought I could get away without needing co. Silly me. Until node.js officially support generator functions across it's entire API, every generator functions will have to get invoked from co to enable this module's functionality.