In the following piece of code the fiber works as expected ("1" and "2" are printed 2 seconds apart). But, I want to return "3" from fiberFunction and print that synchronously. This doesn't work though.Here is the output:
1
Temp: undefined
2
Does anybody know how to return a value from a fiber function?
var Fiber = require('fibers');
var Future = require('fibers/future'), wait = Future.wait;
function sleep(ms) {
var future = new Future;
setTimeout(function() {
future.return();
}, ms);
return future;
}
var fiberFunction = Fiber(function() {
console.log("1");
sleep(2000).wait();
console.log("2");
return "3";
});
var fiberReturn = fiberFunction.run();
console.log("Temp: " + fiberReturn);