Class: AWS::Flow::Core::FiberConditionVariable
- Inherits:
-
Object
- Object
- AWS::Flow::Core::FiberConditionVariable
- Defined in:
- lib/aws/flow/future.rb
Overview
Based on the ruby core source: github.com/ruby/ruby/blob/trunk/lib/thread.rb
Instance Method Summary collapse
-
#broadcast ⇒ Object
Wakes up all fibers waiting for this lock.
-
#initialize ⇒ FiberConditionVariable
constructor
Creates a new ConditionVariable.
-
#signal ⇒ Object
Wakes up the first fiber in line waiting for this lock.
-
#wait ⇒ Object
Have the current fiber wait on this condition variable, and wake up when the FiberConditionVariable is signalled/broadcaster.
Constructor Details
#initialize ⇒ FiberConditionVariable
Creates a new ConditionVariable
82 83 84 |
# File 'lib/aws/flow/future.rb', line 82 def initialize @waiters = [] end |
Instance Method Details
#broadcast ⇒ Object
Wakes up all fibers waiting for this lock.
108 109 110 111 |
# File 'lib/aws/flow/future.rb', line 108 def broadcast signal until @waiters.empty? self end |
#signal ⇒ Object
Wakes up the first fiber in line waiting for this lock.
99 100 101 102 103 |
# File 'lib/aws/flow/future.rb', line 99 def signal t = @waiters.shift t.schedule if t && t.alive? self end |
#wait ⇒ Object
Have the current fiber wait on this condition variable, and wake up when the FiberConditionVariable is signalled/broadcaster
89 90 91 92 93 94 |
# File 'lib/aws/flow/future.rb', line 89 def wait fiber = ::Fiber.current @waiters << fiber Fiber.yield self end |