AsyncGate

A one-shot signal that resumes every waiter when opened.

Opening is permanent and repeatable: later calls to await return immediately. Cancelling a waiting coroutine removes only that waiter.

val gate = AsyncGate()
val job = launch { gate.await(); load() }
waitUntil(1.seconds, observe = { gate.waiterCount }) { it == 1 }
gate.open()

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

Whether open has been called.

Link copied to clipboard

The number of suspended callers, useful for establishing test interleavings.

Functions

Link copied to clipboard
suspend fun await()

Suspends until the gate opens, or throws when the calling coroutine is cancelled.

Link copied to clipboard
fun open()

Opens the gate permanently and resumes every waiter.