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, as_of: nil, scope: 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, as_of: nil, scope: nil) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/hecks/runtime/caller.rb', line 42 def as(role:, actor_id: nil, as_of: nil, scope: nil) previous = Thread.current[:hecks_caller] Thread.current[:hecks_caller] = Current.new( role: role.to_s, actor_id: actor_id&.to_s, as_of: as_of, scope: scope&.to_s ) yield ensure Thread.current[:hecks_caller] = previous end |
.current ⇒ Object
40 |
# File 'lib/hecks/runtime/caller.rb', line 40 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.
57 58 59 60 61 62 63 |
# File 'lib/hecks/runtime/caller.rb', line 57 def without previous = Thread.current[:hecks_caller] Thread.current[:hecks_caller] = nil yield ensure Thread.current[:hecks_caller] = previous end |