Class: Hatchet::ContextVars::SpawnIndexTracker

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeSpawnIndexTracker

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.

Parameters:

  • action_key (String)

    The action key

Returns:

  • (Integer)

    The current spawn index (before increment)



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

#resetObject

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