collectLatest

open fun <T> Flow<T>.collectLatest(deliveryMode: DeliveryMode, action: suspend (T) -> Unit): Job

Subscribes to the given Flow within the coroutine scope of the subscriptionLifecycleOwner, starting the flow only when the lifecycle is started, and executing with the coroutine context of Mavericks' subscriptionCoroutineContextOverride. This can be utilized to create customized subscriptions, for example, to drop the first element in the flow before continuing. This is intended to be used with viewmodel.stateflow.

Parameters

deliveryMode

If UniqueOnly, when this MavericksView goes from a stopped to started lifecycle a value will only be emitted if the value has changed. This is useful for transient views that should only be shown once (toasts, poptarts), or logging. Most other views should use RedeliverOnStart, as when a view is destroyed and recreated the previous state is necessary to recreate the view.

Use uniqueOnly to automatically create a UniqueOnly mode with a unique id for this view.

action

supports cooperative cancellation. The previous action will be cancelled if it is not completed before the next one is emitted.