Class: RobotLab::Streaming::SequenceCounter
- Inherits:
-
Object
- Object
- RobotLab::Streaming::SequenceCounter
- Defined in:
- lib/robot_lab/streaming/sequence_counter.rb
Overview
Monotonic sequence counter for event ordering
Provides globally unique, strictly increasing sequence numbers for event ordering across streaming contexts.
Thread-safe via Mutex.
Instance Method Summary collapse
-
#current ⇒ Integer
Get the current value without incrementing.
-
#initialize(start: 0) ⇒ SequenceCounter
constructor
Creates a new SequenceCounter.
-
#next ⇒ Integer
Get the next sequence number.
-
#reset(value = 0) ⇒ Object
Reset to a specific value.
Constructor Details
#initialize(start: 0) ⇒ SequenceCounter
Creates a new SequenceCounter.
16 17 18 19 |
# File 'lib/robot_lab/streaming/sequence_counter.rb', line 16 def initialize(start: 0) @value = start @mutex = Mutex.new end |
Instance Method Details
#current ⇒ Integer
Get the current value without incrementing
35 36 37 |
# File 'lib/robot_lab/streaming/sequence_counter.rb', line 35 def current @mutex.synchronize { @value } end |
#next ⇒ Integer
Get the next sequence number
25 26 27 28 29 |
# File 'lib/robot_lab/streaming/sequence_counter.rb', line 25 def next @mutex.synchronize do @value += 1 end end |
#reset(value = 0) ⇒ Object
Reset to a specific value
43 44 45 |
# File 'lib/robot_lab/streaming/sequence_counter.rb', line 43 def reset(value = 0) @mutex.synchronize { @value = value } end |