Class: Philiprehberger::TestFactory::Sequence
- Inherits:
-
Object
- Object
- Philiprehberger::TestFactory::Sequence
- Defined in:
- lib/philiprehberger/test_factory/sequence.rb
Overview
Thread-safe auto-incrementing sequence generator.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Sequence
constructor
Create a new sequence.
-
#next ⇒ Object
Increment the counter and return the block result.
Constructor Details
#initialize(&block) ⇒ Sequence
Create a new sequence.
15 16 17 18 19 |
# File 'lib/philiprehberger/test_factory/sequence.rb', line 15 def initialize(&block) @block = block @counter = 0 @mutex = Mutex.new end |
Instance Method Details
#next ⇒ Object
Increment the counter and return the block result.
24 25 26 27 28 29 |
# File 'lib/philiprehberger/test_factory/sequence.rb', line 24 def next @mutex.synchronize do @counter += 1 @block.call(@counter) end end |