onceStateAtLeast

suspend fun <T> LifecycleOwner.onceStateAtLeast(state: Lifecycle.State, cancelWhenBelow: Boolean, block: suspend () -> T): T

Waits until the lifecycle reaches the given state and then runs block.

Parameters

cancelWhenBelow

Pass false to keep the coroutine running even if the state falls below state.