|
ES6 generators are a far cry from Lua's coroutines:
1) ES6 generators require a special function definition.
2) Lua's coroutines are symmetric--yield can return values provided by
resume.
3) ES6 yield can only be used in the generator function, whereas you can
yield from any function in the Lua coroutine call stack.
Furthermore, Lua's coroutine implementation is unique in real-world
languages in that it's stackless--it doesn't rely on the C stack to
implement coroutines, even when using the C API. (Stackless Python is only
stackless for Python code.) That has useful performance, memory, and
debugging characteristics. On some older platforms (notably the old
LinuxThreads implementation) you can't mix POSIX threads with fibers (the
Windows term for application-created C stacks), and in the future this
limitation may return in the form of security measures on more popular
platforms.