Class: Progenitor::Sequence
- Inherits:
-
Object
- Object
- Progenitor::Sequence
- Defined in:
- lib/progenitor/sequence.rb
Instance Method Summary collapse
- #in_sequence(&block) ⇒ Object
-
#initialize(start = 0) ⇒ Sequence
constructor
A new instance of Sequence.
- #next_int ⇒ Object
Constructor Details
#initialize(start = 0) ⇒ Sequence
Returns a new instance of Sequence.
4 5 6 7 |
# File 'lib/progenitor/sequence.rb', line 4 def initialize(start=0) @lock = Mutex.new @current = start end |
Instance Method Details
#in_sequence(&block) ⇒ Object
17 18 19 20 |
# File 'lib/progenitor/sequence.rb', line 17 def in_sequence(&block) value = next_int block.call value end |
#next_int ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/progenitor/sequence.rb', line 9 def next_int @lock.synchronize do value = @current @current += 1 value end end |