Open Burtan opened 2 years ago
Agreed that it must be explicit that last()
shouldn't be used in SharedFlow
, but instead of having different semantics from Flow.last()
, which might be confusing, I'd prefer to have a deprecation error instead, just like it's done on StateFlow.conflate()
:
@Deprecated(
level = DeprecationLevel.ERROR,
message = "Applying 'last' to SharedFlow never returns as SharedFlow never completes normally. Use 'replayCache.last()' for reading the last emitted item in the replay cache.",
replaceWith = ReplaceWith("replayCache.last()")
)
public fun <T> SharedFlow<T>.last(): T = noImpl()
Terminal operators on SharedFlow
never return normally.
This is an open question for us whether we want to maintain the set of all terminal operators as deprecated extensions on SharedFlow
though
Hi,
when using SharedFlows the function last() delivered by Reduce.kt through extensions will never return. It collects the flow and suspends until it is completed, but SharedFlows never complete. For intuitive usage last() in SharedFlows should be a shortcut for replayCache.last()
Thanks!