consume

fun <T> SharedFlow<T>.consume(key: Any?, action: suspend (value: T) -> Unit)

Collects this SharedFlow inside a LaunchedEffect keyed on key, running action for each emitted value via collectLatest — a still-running action from a previous emission is cancelled when a new one arrives, rather than queued. The shared low-level primitive behind observeScreenTileBroadcastChannel and observeSystemBroadcastChannel below.

Parameters

key

restarts the underlying collection (and cancels any in-flight action) whenever it changes, the same as any LaunchedEffect key.

action

run for each collected value.