Module: TcpUserTimeout::Storage

Defined in:
lib/tcp_user_timeout/storage.rb

Overview

Fiber-safe scoped storage. Uses Ruby 3.2+ inheritable fiber storage (Fiber[]) when available so child fibers (e.g. spawned by Async, Falcon) inherit the deadline; falls back to Thread.current[] on older Rubies, which is correct for thread-per-request servers but does not propagate across fibers.

Constant Summary collapse

FIBER_STORAGE =
Fiber.respond_to?(:[])

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



14
15
16
# File 'lib/tcp_user_timeout/storage.rb', line 14

def [](key)
  FIBER_STORAGE ? Fiber[key] : Thread.current[key]
end

.[]=(key, value) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/tcp_user_timeout/storage.rb', line 18

def []=(key, value)
  if FIBER_STORAGE
    Fiber[key] = value
  else
    Thread.current[key] = value
  end
end