Module: Hecks::Runtime::Caller
- Defined in:
- lib/hecks/runtime/caller.rb
Overview
WHO IS DISPATCHING, bound for the duration of a block — the ambient
counterpart to Runtime.with_registry, but Thread.current-backed
rather than a plain module ivar: registry-binding happens at BOOT
time (single-threaded by construction), this happens at DISPATCH
time, which a future per-request caller (docs/rails-integration.md's
still-unbuilt WebDoor) needs to bind safely under concurrency.
A child Thread.new spawned mid-block does not inherit this — plain
Ruby thread-local semantics — but nothing in this codebase spawns a
worker thread mid-dispatch today, so this is a fact worth naming
rather than a gap worth solving.
Defined Under Namespace
Classes: Current
Class Method Summary collapse
- .as(role:, actor_id: nil) ⇒ Object
- .current ⇒ Object
-
.without ⇒ Object
A REACTION IS THE SYSTEM ACTING, not the caller who happened to be on the stack when the triggering command ran —
Dispatcher#reenterclears the ambient caller around a reaction's own dispatch so a triggering caller's role can neither satisfy nor block a reaction command it has nothing to do with.
Class Method Details
.as(role:, actor_id: nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/hecks/runtime/caller.rb', line 28 def as(role:, actor_id: nil) previous = Thread.current[:hecks_caller] Thread.current[:hecks_caller] = Current.new(role: role.to_s, actor_id: actor_id&.to_s) yield ensure Thread.current[:hecks_caller] = previous end |
.current ⇒ Object
26 |
# File 'lib/hecks/runtime/caller.rb', line 26 def current = Thread.current[:hecks_caller] |
.without ⇒ Object
A REACTION IS THE SYSTEM ACTING, not the caller who happened to be
on the stack when the triggering command ran — Dispatcher#reenter
clears the ambient caller around a reaction's own dispatch so a
triggering caller's role can neither satisfy nor block a reaction
command it has nothing to do with.
41 42 43 44 45 46 47 |
# File 'lib/hecks/runtime/caller.rb', line 41 def without previous = Thread.current[:hecks_caller] Thread.current[:hecks_caller] = nil yield ensure Thread.current[:hecks_caller] = previous end |