class WaitGroup
- WaitGroup
- Reference
- Object
Overview
WaitGroup can be used to wait for a number of different fibers to complete.
Multiple fibers can be waited for, and multiple fibers can be waiting. Once there are no fibers being waited for
wg = WaitGroup.new
wg.spawn do
sleep 1
puts "slept for 1"
end
wg.add
spawn do
sleep 2
puts "slept for 2"
wg.done
end
wg.wait
puts "done waiting"
Defined in:
crystal-wait-group.crInstance Method Summary
-
#add(delta = 1)
Add
delta
to the number of fibers being waited for. -
#done
Decrease the number of fibers being waited for by 1.
- #spawn(&block)
- #unwait
-
#wait
Pause the current fiber until there are no fibers being waited for.
Instance Method Detail
def add(delta = 1)
#
Add delta
to the number of fibers being waited for.
Delta should be positive. Use #done
instead to decrement the counter.
def done
#
Decrease the number of fibers being waited for by 1.
This should be called from within the spawned fiber that's being waited for. Once there are 0 fibers being waited for, all waiting fibers will be restarted.
Raises an error if the counter goes below 0.
def spawn(&block)
#