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.
CoroutineLatch(initial: Int)
A latch. |
val count: Int
The current latch count. |
|
val isOpen: Boolean
Indicates if the latch is open ( |
suspend fun await(): Unit
Await the latch opening. If already open, return without suspending. |
|
fun countDown(): Boolean
Decrease the latch count, potentially opening the latch and awakening suspending co-routines. |
|
fun countUp(): Boolean
Increase the latch count, potentially closing the latch. |