Class: Async::Waiter Deprecated
- Inherits:
-
Object
- Object
- Async::Waiter
- Defined in:
- lib/async/waiter.rb
Overview
Instance Method Summary collapse
-
#async(parent: (@parent or Task.current), **options, &block) ⇒ Object
Execute a child task and add it to the waiter.
-
#first(count = nil) ⇒ Object
Wait for the first ‘count` tasks to complete.
-
#initialize(parent: nil, finished: Async::Condition.new) ⇒ Waiter
constructor
Create a waiter instance.
-
#wait(count = nil) ⇒ Object
Wait for the first ‘count` tasks to complete.
Constructor Details
#initialize(parent: nil, finished: Async::Condition.new) ⇒ Waiter
Create a waiter instance.
17 18 19 20 21 22 23 24 |
# File 'lib/async/waiter.rb', line 17 def initialize(parent: nil, finished: Async::Condition.new) warn("`Async::Waiter` is deprecated, use `Async::Barrier` instead.", uplevel: 1, category: :deprecated) if $VERBOSE @finished = finished @done = [] @parent = parent end |
Instance Method Details
#async(parent: (@parent or Task.current), **options, &block) ⇒ Object
Execute a child task and add it to the waiter.
28 29 30 31 32 33 34 35 |
# File 'lib/async/waiter.rb', line 28 def async(parent: (@parent or Task.current), **, &block) parent.async(**) do |task| yield(task) ensure @done << task @finished.signal end end |
#first(count = nil) ⇒ Object
Wait for the first ‘count` tasks to complete.
41 42 43 44 45 46 47 48 49 |
# File 'lib/async/waiter.rb', line 41 def first(count = nil) minimum = count || 1 while @done.size < minimum @finished.wait end return @done.shift(*count) end |
#wait(count = nil) ⇒ Object
Wait for the first ‘count` tasks to complete.
53 54 55 56 57 58 59 |
# File 'lib/async/waiter.rb', line 53 def wait(count = nil) if count first(count).map(&:wait) else first.wait end end |