Explaining Ruby Fibers
noteflakes.com
noteflakes.com
https://github.com/digital-fabric
Sharon is essentially developing a whole new stack of Ruby core libraries updated to feel more 2021 web than 2006 web (but in a good way). There’s a lot of neat stuff here to explore.
He has great taste!
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.OTOH Ruby’s fibers also provide a symmetric `transfer(fiber)` function. Asymmetric and symmetric coroutines are equivalent, so presumably Ruby implements one in terms of the other - it would be interesting to find out exactly how that was done.