class CoroutineLatch
(source)
A co-routine synchronization aid that allows co-routines to wait until a set of operations being performed has completed.
The latch is initialized with a given count. If the latch count is greater than zero, the await()
method will
suspend until the count reaches zero due to invocations of the countDown()
method, at which point all suspended
co-routines will be resumed.
Unlike the Java CountDownLatch
, this latch allows the count to be increased via invocation of the countUp()
method. Increasing the count from zero will result in calls to await()
suspending again. Note that the count may
be negative, requiring multiple calls to countUp()
before calls to await()
suspend.
initial
- The initial count of the latch, which may be positive, zero, or negative.
<init> |
A latch. CoroutineLatch(initial: Int) |
count |
The current latch count. val count: Int |
isOpen |
Indicates if the latch is open ( val isOpen: Boolean |
await |
Await the latch opening. If already open, return without suspending. suspend fun await(): Unit |
countDown |
Decrease the latch count, potentially opening the latch and awakening suspending co-routines. fun countDown(): Boolean |
countUp |
Increase the latch count, potentially closing the latch. fun countUp(): Boolean |