Class: Async::Variable
- Inherits:
- 
      Object
      
        - Object
- Async::Variable
 
- Defined in:
- lib/async/variable.rb
Overview
A synchronization primitive that allows one task to wait for another task to resolve a value.
Instance Method Summary collapse
- 
  
    
      #initialize(condition = Condition.new)  ⇒ Variable 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Create a new variable. 
- 
  
    
      #resolve(value = true)  ⇒ Object 
    
    
      (also: #value=)
    
  
  
  
  
  
  
  
  
  
    Resolve the value. 
- 
  
    
      #resolved?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Whether the value has been resolved. 
- 
  
    
      #wait  ⇒ Object 
    
    
      (also: #value)
    
  
  
  
  
  
  
  
  
  
    Wait for the value to be resolved. 
Constructor Details
Instance Method Details
#resolve(value = true) ⇒ Object Also known as: value=
Resolve the value.
Signals all waiting tasks.
| 24 25 26 27 28 29 30 31 32 | # File 'lib/async/variable.rb', line 24 def resolve(value = true) @value = value condition = @condition @condition = nil self.freeze condition.signal(value) end | 
#resolved? ⇒ Boolean
Whether the value has been resolved.
| 39 40 41 | # File 'lib/async/variable.rb', line 39 def resolved? @condition.nil? end | 
#wait ⇒ Object Also known as: value
Wait for the value to be resolved.
| 46 47 48 49 | # File 'lib/async/variable.rb', line 46 def wait @condition&.wait return @value end |