Class: Hatchet::ContextVars::SpawnIndexTracker
- Inherits:
-
Object
- Object
- Hatchet::ContextVars::SpawnIndexTracker
- Defined in:
- lib/hatchet/context_vars.rb
Overview
Thread-safe counter for tracking spawn indices per action key. This provides deterministic child_index values for replay consistency.
Instance Method Summary collapse
-
#initialize ⇒ SpawnIndexTracker
constructor
A new instance of SpawnIndexTracker.
-
#next_index(action_key) ⇒ Integer
Get and increment the spawn index for the given action key.
-
#reset ⇒ Object
Reset the counter (e.g., between test runs).
Constructor Details
#initialize ⇒ SpawnIndexTracker
Returns a new instance of SpawnIndexTracker.
96 97 98 99 |
# File 'lib/hatchet/context_vars.rb', line 96 def initialize @mutex = Mutex.new @indices = Hash.new(0) end |
Instance Method Details
#next_index(action_key) ⇒ Integer
Get and increment the spawn index for the given action key.
105 106 107 108 109 110 111 |
# File 'lib/hatchet/context_vars.rb', line 105 def next_index(action_key) @mutex.synchronize do index = @indices[action_key] @indices[action_key] = index + 1 index end end |
#reset ⇒ Object
Reset the counter (e.g., between test runs)
114 115 116 |
# File 'lib/hatchet/context_vars.rb', line 114 def reset @mutex.synchronize { @indices.clear } end |