Class: Async::Condition
- Inherits:
- 
      Object
      
        - Object
- Async::Condition
 
- Defined in:
- lib/async/condition.rb
Overview
A synchronization primitive, which allows fibers to wait until a particular condition is (edge) triggered.
Direct Known Subclasses
Instance Method Summary collapse
- 
  
    
      #empty?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  deprecated
  
  
    Deprecated. Replaced by #waiting? 
- 
  
    
      #initialize  ⇒ Condition 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Create a new condition. 
- 
  
    
      #signal(value = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Signal to a given task that it should resume operations. 
- 
  
    
      #wait  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Queue up the current fiber and wait on yielding the task. 
- #waiting? ⇒ Boolean
Constructor Details
Instance Method Details
#empty? ⇒ Boolean
Deprecated. 
  Replaced by #waiting?
| 44 45 46 | # File 'lib/async/condition.rb', line 44 def empty? @waiting.empty? end | 
#signal(value = nil) ⇒ Object
Signal to a given task that it should resume operations.
| 55 56 57 58 59 60 61 62 63 64 65 | # File 'lib/async/condition.rb', line 55 def signal(value = nil) return if @waiting.empty? waiting = self.exchange waiting.each do |fiber| Fiber.scheduler.resume(fiber, value) if fiber.alive? end return nil end | 
#wait ⇒ Object
Queue up the current fiber and wait on yielding the task.
| 37 38 39 40 41 | # File 'lib/async/condition.rb', line 37 def wait @waiting.stack(FiberNode.new(Fiber.current)) do Fiber.scheduler.transfer end end | 
#waiting? ⇒ Boolean
| 49 50 51 | # File 'lib/async/condition.rb', line 49 def waiting? @waiting.size > 0 end |