4 ms·
Just for the note, in JS these two: async function foo() {...} function* bar() {...} // a.k.a. generator are fibers. These are execution contexts that
by c-smile 5y ago
Just for the note, in JS these two:
async function foo() {...}
function* bar() {...} // a.k.a. generator
are fibers. These are execution contexts that JS VM can be switched into. The first one (asynchronous function) uses kind-of preemptive multitasking (implicit context switch) and generators are closer to canonical fibers - cooperative multitasking with explicit yield of VM to other fibers.
- pansa2 5y agoAsync functions and generators, in both JavaScript and Python, are forms of (asymmetric) stackless coroutines. Usually the term “fiber” is only used for stackful coroutines.
- fzzzy 5y agoFibers are symmetrical coroutines, generators and async functions are asymmetrical coroutines. They are slightly different.