Concurrent::CountDownLatch
Inherits Reference / Object
Allows fibers to wait until a series of operations performed in other fibers complete.
This class has additional capabilities not found in java or other implementations:
wait_countmay be set at initialization or if not provided to initialize() any time after (only once between resets).- Reset is allowed after the latch is released. The object may be reused but is not a cyclic barrier.
A single atomic counter is used. This implementation is 30-40% faster than using a Mutex or Channel::Buffered on Crystal 0.29.0-dev and likely to be faster still when channels are thread safe.
Constructors
new(saved_wait_count : Int32 = 0)
SourceInstance methods
count_down
Sourcecount_up(n = 1) : Nil
Sourceerror(ex : Exception) : Nil
Use instead of count_down. Stores the first error and raises it when #wait is called.
reset
Only call reset after latch is released or after initialize. Undefined behavior if called between use of count_down and release.
wait_count
Sourcewait_count=(wait_count : Int32) : Int32
Must be set exactly once and only if not supplied to #initialize