Class: Dynflow::RoundRobin
- Inherits:
-
Object
- Object
- Dynflow::RoundRobin
- Defined in:
- lib/dynflow/round_robin.rb
Overview
A simple round-robin scheduling implementation used at various places in Dynflow
Instance Attribute Summary collapse
-
#data ⇒ Object
writeonly
the ‘add` and `delete` methods should be preferred, but sometimes the list of things to iterate though can not be owned by the round robin object itself.
Instance Method Summary collapse
- #add(item) ⇒ Object
- #delete(item) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ RoundRobin
constructor
A new instance of RoundRobin.
- #next ⇒ Object
Constructor Details
#initialize ⇒ RoundRobin
Returns a new instance of RoundRobin.
7 8 9 10 |
# File 'lib/dynflow/round_robin.rb', line 7 def initialize @data = [] @cursor = 0 end |
Instance Attribute Details
#data=(value) ⇒ Object (writeonly)
the ‘add` and `delete` methods should be preferred, but sometimes the list of things to iterate though can not be owned by the round robin object itself
36 37 38 |
# File 'lib/dynflow/round_robin.rb', line 36 def data=(value) @data = value end |
Instance Method Details
#add(item) ⇒ Object
12 13 14 15 |
# File 'lib/dynflow/round_robin.rb', line 12 def add(item) @data.push item self end |
#delete(item) ⇒ Object
17 18 19 20 |
# File 'lib/dynflow/round_robin.rb', line 17 def delete(item) @data.delete item self end |
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/dynflow/round_robin.rb', line 29 def empty? @data.empty? end |
#next ⇒ Object
22 23 24 25 26 27 |
# File 'lib/dynflow/round_robin.rb', line 22 def next @cursor = 0 if @cursor > @data.size - 1 @data[@cursor] ensure @cursor += 1 end |