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.



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

Returns:

  • (Boolean)


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

def empty?
  @data.empty?
end

#nextObject



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