flowWhenStarted

fun <T> Flow<T>.flowWhenStarted(owner: LifecycleOwner): Flow<T>

Emits values from the source flow only when the owner is started. When the owner transitions to started, the most recent value will be emitted.

Implementation is similar to combineTransform with the following changes:

  1. Regular channels are used instead of fair channels to avoid unnecessary yield calls. It's possible because lifecycle state updated in the main thread

  2. Flow completes when either this flow completes or lifecycle is destroyed