Class: Dynflow::RoundRobin

Inherits:
Object
  • Object
show all
Defined in:
lib/dynflow/round_robin.rb

Overview

A simple round-robin scheduling implementation used at various places in Dynflow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoundRobin

Returns a new instance of RoundRobin.



6
7
8
9
# File 'lib/dynflow/round_robin.rb', line 6

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



35
36
37
# File 'lib/dynflow/round_robin.rb', line 35

def data=(value)
  @data = value
end

Instance Method Details

#add(item) ⇒ Object



11
12
13
14
# File 'lib/dynflow/round_robin.rb', line 11

def add(item)
  @data.push item
  self
end

#delete(item) ⇒ Object



16
17
18
19
# File 'lib/dynflow/round_robin.rb', line 16

def delete(item)
  @data.delete item
  self
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dynflow/round_robin.rb', line 28

def empty?
  @data.empty?
end

#nextObject



21
22
23
24
25
26
# File 'lib/dynflow/round_robin.rb', line 21

def next
  @cursor = 0 if @cursor > @data.size-1
  @data[@cursor]
ensure
  @cursor += 1
end