Closed ioquatix closed 1 year ago
I'm not sure if the name of this is class is correct. Async::Waiter
just seems too generic.
If you only care about waiting for some subset of tasks, this + a semaphore is probably more useful than a barrier. I think they serve different purposes.
I like this implementation better 👍
Async::Waiter just seems too generic
Yes, and also the first association for waiter is that is should serve something
Maybe Async::Moat
?
Async::FinishLine
Async::Winners
Async::Deadline
Async::Goal
Async::Race
(used in JS?)Async::Battle
Async::Butler
Async::Completions
Async::LimitedBarrier
(similar to Async::LimitedQueue
)For deadline scheduling, it could also be useful:
barrier = Async::Barrier.new
waiter = Async::Waiter.new(parent: barrier)
urls.each{|url| waiter.async{... url ...}}
waiter.each(timeout: 5) do
# Process as many completions as possible within 5 seconds
end
barrier.stop # kill all remaining tasks
Async::LimitedBarrier
sounds the best IMO.
I like this implementation and Async::LimitedBarrier
seems to be a good name IMO
See https://github.com/socketry/async/pull/174 for a slightly different implementation.
@bruno- @zhulik what do you think of this? You can compose it with barrier if you need a final wait-all, which simplifies the implementation and also makes it composable with semaphore, etc.