DeviceBarrier

class DeviceBarrier(val parties: Int, val oneShot: Boolean = false)(source)

Coroutine coordination for simultaneous multi-device phases. All waiting is suspension (await), never thread blocking, and cancellation is safe: a waiter cancelled before the barrier trips leaves the barrier intact for the rest.

Two semantics, chosen at construction and documented here because mixing them is the usual bug:

  • Reusable (default, oneShot = false): every parties arrivals trip the barrier and immediately reset it for the next round. Use when several phases must each start together (for example "both devices ready, then both tap").

  • One-shot (oneShot = true): the first parties arrivals trip once; every later await returns immediately. Use for a single rendezvous ("both sessions open before any device acts"). It never resets. After the release waiting reports zero: the trip clears the arrival count (the tripped gate is kept, so late arrivals still pass through).

Backend propagation still uses the observing device's UI condition, not a barrier: use a barrier only when the test genuinely needs simultaneity (both sides ready before either proceeds). A barrier never carries data and never replaces coroutineScope/async for fan-out; sibling failure still cancels the scope, including waiters parked in await.

Constructors

Link copied to clipboard
constructor(parties: Int, oneShot: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun await()

Waits until parties callers have arrived. The last arrival trips the barrier and returns without suspending; the rest suspend until then. Cancellation before the trip removes the arrival so the barrier still needs a full parties; cancellation after the trip is too late (the call already returned). Never blocks a thread.

Link copied to clipboard
suspend fun waiting(): Int

Arrivals currently waiting in this round (diagnostics).