awaitRunOn

inline suspend fun <S : Any, T : S> Flow<S>.awaitRunOn(crossinline predicate: (T) -> Boolean = { true }, crossinline block: suspend (capturedState: T) -> Unit)(source)

This API is intended to simplify and add type-safety to working with sealed class states. This can be applied to any Flow of states, not just the OrbitContainer's own. The main purpose of this API is to help you work with child container states.

Suspends until the state becomes the given subtype and the given predicate matches, then executes the given block.

The block will be cancelled as soon as the state changes to a different type or the predicate does not return true. Note that this does not guarantee the operation in the block is atomic.

The state is captured and does not change within this block.

Unlike runOn, this function does not complete immediately if the current state does not match. Instead, it suspends until the state becomes the given subtype.

Parameters

predicate

optional predicate to match the state against. Defaults to true.