Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Sometimes Fiber.run() returns before yield #178

Closed
veselov opened this Issue Jul 16, 2014 · 2 comments

Comments

Projects
None yet
3 participants

veselov commented Jul 16, 2014

Hi.

I was able to distill this. The following code shows run() returning before yield():

var Fiber = require('fibers');
var Future = require('fibers/future');

Fiber(function(){
    console.log("fiber started");
    var f = new Future();
    setTimeout(function(){f.return(0);}, 1000);
    console.log("about to wait");
    f.wait();
    console.log("future returned");
    Fiber.yield(Fiber.current);
}).run().reset();
console.log("main() done");

The documentation for run() states:

This function will return either the parameter passed to yield(), or the returned value from the fiber's main function.

The documentation for Future.prototype.wait() doesn't say that it will internally make the Fiber yield.

[pawel@druid]~/ws/capi$ node 3.js 
fiber started
about to wait

/home/pawel/ws/capi/3.js:15
}).run().reset();
         ^
TypeError: Cannot call method 'reset' of undefined
    at Object.<anonymous> (/home/pawel/ws/capi/3.js:15:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
[pawel@druid]~/ws/capi$ 

node: v0.10.29
fibers: 1.0.1

glasser commented Dec 12, 2014

Yes, but that is how Future works...

Owner

laverdet commented Dec 18, 2014

Yeah you should only use Fiber or Future one at a time. I think most users should use only Future, as direct use of Fiber will get you into situations like this.

@laverdet laverdet closed this Dec 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment