Class: QuackConcurrency::Waiter
- Inherits:
-
ConcurrencyTool
- Object
- ConcurrencyTool
- QuackConcurrency::Waiter
- Defined in:
- lib/quack_concurrency/waiter.rb
Instance Method Summary collapse
-
#initialize(duck_types: nil) ⇒ Waiter
constructor
Creates a new Waiter concurrency tool.
-
#resume(value = nil) ⇒ void
Resumes next waiting thread.
-
#wait ⇒ Object
Waits for another thread to resume the calling thread.
Methods inherited from ConcurrencyTool
Constructor Details
#initialize(duck_types: nil) ⇒ Waiter
Creates a new QuackConcurrency::Waiter concurrency tool.
8 9 10 |
# File 'lib/quack_concurrency/waiter.rb', line 8 def initialize(duck_types: nil) @queue = Queue.new(duck_types: duck_types) end |
Instance Method Details
#resume(value = nil) ⇒ void
This method returns an undefined value.
Resumes next waiting thread.
15 16 17 18 |
# File 'lib/quack_concurrency/waiter.rb', line 15 def resume(value = nil) @queue << value nil end |
#wait ⇒ Object
Note:
Will block until resumed.
Waits for another thread to resume the calling thread.
23 24 25 |
# File 'lib/quack_concurrency/waiter.rb', line 23 def wait @queue.pop end |