module RequestStore::Fibers

Make RequestStore work with fibers.

Constants

VERSION

Public Class Methods

init() click to toggle source
# File lib/request_store/fibers.rb, line 12
def self.init
  @hook_id = Fiber.hook(
    new: -> { [RequestStore.store, RequestStore.active?] },
    resume: ->(value) {
      RequestStore.store = value[0]
      if value[1]
        RequestStore.begin!
      else
        RequestStore.end!
      end
    }
  )
end
uninit() click to toggle source
# File lib/request_store/fibers.rb, line 26
def self.uninit
  raise Error, "You must init before you can uninit" unless @hook_id

  Fiber.unhook(@hook_id)
  @hook_id = nil
end