Module: Karst::ExecutionContext

Defined in:
lib/karst/execution_context.rb

Overview

Request-local correlation storage used by the page badge to carry evidence from a notification callback fired inside a Rack call back out to the code that reads it, without a global mutable variable that would let concurrent requests cross-contaminate each other.

Modern Rails already solves exactly this with ActiveSupport::IsolatedExecutionState, so Karst simply delegates to it when present. Rails 6.1 does not provide that API, so Karst falls back to ThreadLocalStore, a plain per-Thread Hash reached through Thread#thread_variable_get/set -- never Thread#[]/[]=, which are fiber-local and would silently miss context under a Fiber scheduler. This mirrors ActiveSupport::IsolatedExecutionState's own default :thread isolation level: storage is shared by every Fiber running on one OS thread, not isolated per Fiber. Karst's own usage (one badge correlation captured and read back within a single synchronous request) never spans multiple concurrently-scheduled Fibers, so this fallback has no observable effect on Karst's supported behavior. It is documented here so a future caller does not assume Fiber isolation this fallback cannot provide.

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



69
70
71
# File 'lib/karst/execution_context.rb', line 69

def [](key)
  BACKEND[key]
end

.[]=(key, value) ⇒ Object



73
74
75
# File 'lib/karst/execution_context.rb', line 73

def []=(key, value)
  BACKEND[key] = value
end

.delete(key) ⇒ Object



77
78
79
# File 'lib/karst/execution_context.rb', line 77

def delete(key)
  BACKEND.delete(key)
end