维基百科建议coroutines can be implemented with generators。这是否意味着可以使用ES6 generators实现node-fibers
发布于 2014-01-03 08:12:41
你在找像https://github.com/visionmedia/co这样的东西吗?
从自述文件中:
var co = require('co');
co(function *(){
var a = yield get('http://google.com');
var b = yield get('http://yahoo.com');
var c = yield get('http://cloudup.com');
console.log(a.status);
console.log(b.status);
console.log(c.status);
})()
co(function *(){
var a = get('http://google.com');
var b = get('http://yahoo.com');
var c = get('http://cloudup.com');
var res = yield [a, b, c];
console.log(res);
})()有一个新的web框架叫做koa (http://koajs.com),它就是基于这一点。
发布于 2014-05-01 12:42:36
我在纤程周围编写了一个名为wait.for:https://github.com/luciotato/waitfor的包装器
然后我用生成器编写了相同的功能:https://github.com/luciotato/waitfor-ES6
您可以对两者进行比较,以了解生成器如何用不同的语法替换node-Fiber。
一个重要的区别是,ES6的生成器主体是用一种特殊的语法实现的:function*,而node-fibers允许您使用任何js函数。
发布于 2013-08-18 05:41:10
I tried to port a very small subset并失败。问题的症结在于,node-fibers的Fiber.yield()会停止执行光纤的所有调用堆栈,而生成器的yield只会暂停立即函数。虽然您可以实现一个行为类似的系统(如Task.js),但似乎不可能实现与API兼容的实现。
https://stackoverflow.com/questions/18293563
复制相似问题