-
I'm struggling to find out whether Flipper should be able to memoize during the usage of Fibers within a single thread. We just happen to use
I notice > Flipper.instance.__id__
=> 418860
> Fiber.new { puts Flipper.instance.__id__ }.resume
470320
> Fiber.new { puts Flipper.instance.__id__ }.resume
475280
> Flipper.instance.__id__
=> 418860 I understand if catering to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I'm not sure I gave enough detail to highlight why the default rails memoization is broken in Fibers. The flipper rack middleware sets # this is in the rack middleware, wrapping the request
> Flipper.memoize = true
=> true
> Flipper.memoizing?
=> true
# graphql kicks off execution, and simulating being in a fiber trying to do *any* memoization
> Fiber.new { Flipper.memoizing? }.resume
=> false |
Beta Was this translation helpful? Give feedback.
-
Ah, here is what I was missing: def spawn_fiber
fiber_vars = get_fiber_variables
Fiber.new(blocking: !@nonblocking) {
set_fiber_variables(fiber_vars) |
Beta Was this translation helpful? Give feedback.
Ah, here is what I was missing:
graphql-ruby
has implemented a bridge across this gap, and copies Thread locals to Fibers upon creation:taken from https://github.com/rmosolgo/graphql-ruby/blob/5dcdb597c4dd9dc943b8a86f11c271a32d2a97a4/lib/graphql/dataloader.rb#L65-L77