lib/async/waiter.rb in async-2.12.1 vs lib/async/waiter.rb in async-2.13.0
- old
+ new
@@ -4,20 +4,24 @@
# Copyright, 2022, by Samuel Williams.
module Async
# A composable synchronization primitive, which allows one task to wait for a number of other tasks to complete. It can be used in conjunction with {Semaphore} and/or {Barrier}.
class Waiter
+ # Create a waiter instance.
+ #
+ # @parameter parent [Interface(:async) | Nil] The parent task to use for asynchronous operations.
+ # @parameter finished [Async::Condition] The condition to signal when a task completes.
def initialize(parent: nil, finished: Async::Condition.new)
@finished = finished
@done = []
@parent = parent
end
# Execute a child task and add it to the waiter.
# @asynchronous Executes the given block concurrently.
- def async(parent: (@parent or Task.current), &block)
- parent.async do |task|
+ def async(parent: (@parent or Task.current), **options, &block)
+ parent.async(**options) do |task|
yield(task)
ensure
@done << task
@finished.signal
end