Wikipedia suggests that coroutines can be implemented with generators. Does this mean node-fibers could be implemented using ES6 generators?
Can node-fibers be implemented using ES6 generators?
1.1k views Asked by hurrymaplelad AtThere are 3 answers
I tried to port a very small subset and failed. The crux was that node-fibers's Fiber.yield()
halts execution all the way up the Fiber's call stack, while a generator's yield
only halts the immediate function. While you may be able to implement a system that behaves similarly (like Task.js), it seems an API compatible implementation is impossible.
I've coded a wrapper around Fibers called wait.for: https://github.com/luciotato/waitfor
Then I've coded the same functionality with generators: https://github.com/luciotato/waitfor-ES6
You can compare both to see how Generators can replace node-Fibers, but with different syntax.
One important difference, which makes impossible to have the same API,
is that ES6's generators bodies are implemented with a special syntax: function*
while node-fibers allows you use any js function.
Are you looking for something like https://github.com/visionmedia/co ?
From the README:
There is a new web framework called koa (http://koajs.com) that's based on this.