-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
More Ruby libraries are beginning to embrace fibers as concurrency primitives. One recent example is Falcon – "a multi-process, multi-fiber rack-compatible HTTP server."
Because Mongoid now uses fibers as a tool for executing recursive around callbacks on embedded children, any Mongoid app that uses these callbacks will be incompatible with Falcon (and other fiber-oriented Ruby libraries). As compelling as the fiber solution was to our around callback problem, it does not seem to be a long-term solution.
Being able to flatten a recursive call-stack was a powerful feature. Are there other libraries out there that let us do that? Some possible things to investigate:
- Continuations (though, are these deprecated in newer Ruby versions?)
- Ractor
- Enumerator (though, it sounds like these use fibers under the hood, too?)
- Are there any third-party solutions that provide this functionality (letting us effectively pause a block when yield is invoked, and manually continuing it later)?
Alternatively:
- Can we rework the local storage mechanism that Mongoid uses ("Threaded" module) so that it is both thread-safe and fiber-safe? Tools like Falcon want Fiber-local storage, so that multiple fibers running in parallel keep their state separate; Mongoid's Thread-local storage falls down in this case. But storing state in Fiber-local storage is problematic because then it becomes invisible inside other fibers (including, perhaps, Enumerables?)
- Worst case: we disallow around callbacks on embedded children. If someone wants an around callback on an embedded child, they have to implement it as a pair of before and after callbacks instead.