我有一个关于Nodejs Fibers的问题(这对我来说绝对是新的)...我有Nodejs Fibers的教程,http: //bjouhier.wordpress.com/2012/03/11/fibers-and-threads-in- node-js-what-for /,这里有一个例子
var fiber = Fiber.current;
db.connect(function(err, conn) {
if (err) return fiber.throwInto(err);
fiber.run(conn);
});
// Next line will yield until fiber.throwInto
// or fiber.run are called
var c = Fiber.yield();
// If fiber.throwInto was called we don't reach this point
// because the previous line throws.
// So we only get here if fiber.run was called and then
// c receives the conn value.
doSomething(c);
// Problem solved!
Run Code Online (Sandbox Code Playgroud)
现在基于这个例子,我创建了我自己的代码版本,
var Fiber = require('fibers'); …Run Code Online (Sandbox Code Playgroud)