class Dynflow::Semaphores::Aggregating
Attributes
children[R]
waiting[R]
Public Class Methods
new(children)
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 8 def initialize(children) @children = children @waiting = [] end
Public Instance Methods
drain()
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 44 def drain available = free @children.values.each { |child| child.get available } available end
free()
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 50 def free @children.values.map(&:free).reduce { |acc, cur| cur < acc ? cur : acc } end
get(n = 1)
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 34 def get(n = 1) available = free if n > available drain else @children.values.each { |child| child.get n } n end end
get_waiting()
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 22 def get_waiting @waiting.shift end
has_waiting?()
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 26 def has_waiting? !@waiting.empty? end
release(n = 1, key = nil)
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 54 def release(n = 1, key = nil) if key.nil? @children.values.each { |child| child.release n } else @children[key].release n end end
save()
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 30 def save @children.values.each(&:save) end
wait(thing)
click to toggle source
# File lib/dynflow/semaphores/aggregating.rb, line 13 def wait(thing) if get > 0 true else @waiting << thing false end end