crystal
crystal copied to clipboard
Add `ExecutionContext` support to `WaitGroup`
trafficstars
With ExecutionContext soon being available I think it would be nice to be able to pass an optional ExecutionContext to WaitGroup in which the WG till spawn fibers.
I'd like to do something like
ec = ExecutionContext::MultiThreaded.new("workers", 4)
WaitGroup.wait(ec) do |wg|
items.each { |i| wg.spawn worker(i) }
end
instead of
ec = ExecutionContext::MultiThreaded.new("workers", 4)
ec_wg = WaitGroup.new(1)
ec.spawn do
WaitGroup.wait do |wg|
items.each { |i| wg.spawn worker(i) }
end
ec_wg.done
end
ec_wg.wait
I guess it would be nice to be able to pass an EC to the constructor as well.