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
76 77 78 |
# File 'lib/aws/flow/future.rb', line 76 def initialize @waiters = [] end |
Instance Method Details
#broadcast ⇒ Object
Wakes up all fibers waiting for this lock.
102 103 104 105 |
# File 'lib/aws/flow/future.rb', line 102 def broadcast signal until @waiters.empty? self end |
#signal ⇒ Object
Wakes up the first fiber in line waiting for this lock.
93 94 95 96 97 |
# File 'lib/aws/flow/future.rb', line 93 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
83 84 85 86 87 88 |
# File 'lib/aws/flow/future.rb', line 83 def wait fiber = ::Fiber.current @waiters << fiber Fiber.yield self end |