ConditionalValue

open class ConditionalValue<T>(initValue: T)

A coroutine-based conditional waiter backed by MutableStateFlow.

Holds a value of type T and allows coroutines to suspend until the value satisfies an arbitrary predicate, with optional timeout support.

Parameters

initValue

the initial value.

Type Parameters

T

the type of the monitored value.

Inheritors

Constructors

Link copied to clipboard
constructor(initValue: T)

Functions

Link copied to clipboard
fun get(): T

Returns the current value.

Link copied to clipboard
suspend fun set(value: T)

Sets the value and yields to allow waiting coroutines to observe the change.

Link copied to clipboard
suspend fun waitUntil(timeoutDuration: Duration = Duration.INFINITE, predicate: (T) -> Boolean): Boolean

Suspends until the predicate becomes true or timeout occurs.