Class: Dynflow::Semaphores::Aggregating
- Defined in:
 - lib/dynflow/semaphores/aggregating.rb
 
Instance Attribute Summary collapse
- 
  
    
      #children  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute children.
 - 
  
    
      #waiting  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute waiting.
 
Instance Method Summary collapse
- #drain ⇒ Object
 - #free ⇒ Object
 - #get(n = 1) ⇒ Object
 - #get_waiting ⇒ Object
 - #has_waiting? ⇒ Boolean
 - 
  
    
      #initialize(children)  ⇒ Aggregating 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Aggregating.
 - #release(n = 1, key = nil) ⇒ Object
 - #save ⇒ Object
 - #wait(thing) ⇒ Object
 
Constructor Details
#initialize(children) ⇒ Aggregating
Returns a new instance of Aggregating.
      8 9 10 11  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 8 def initialize(children) @children = children @waiting = [] end  | 
  
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
      6 7 8  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 6 def children @children end  | 
  
#waiting ⇒ Object (readonly)
Returns the value of attribute waiting.
      6 7 8  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 6 def waiting @waiting end  | 
  
Instance Method Details
#drain ⇒ Object
      44 45 46 47 48  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 44 def drain available = free @children.values.each { |child| child.get available } available end  | 
  
#free ⇒ Object
      50 51 52  | 
    
      # 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) ⇒ Object
      34 35 36 37 38 39 40 41 42  | 
    
      # 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 ⇒ Object
      22 23 24  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 22 def get_waiting @waiting.shift end  | 
  
#has_waiting? ⇒ Boolean
      26 27 28  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 26 def has_waiting? !@waiting.empty? end  | 
  
#release(n = 1, key = nil) ⇒ Object
      54 55 56 57 58 59 60  | 
    
      # 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 ⇒ Object
      30 31 32  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 30 def save @children.values.each(&:save) end  | 
  
#wait(thing) ⇒ Object
      13 14 15 16 17 18 19 20  | 
    
      # File 'lib/dynflow/semaphores/aggregating.rb', line 13 def wait(thing) if get > 0 true else @waiting << thing false end end  |