efemoney
08/14/2021, 10:55 AMStateFlow
) … will this be a good way?
interface RefreshableFlow: Flow (or SharedFlow or StateFlow) {
fun refresh()
}
class RefreshableFlowImpl(val delegate: flow): Flow by flow, RefreshableFlow {
override fun refresh() { ... } // launch coroutine/send event/etc that would eventually or not emit a new value
}
What are the pitfalls of doing something like this?Erik
08/14/2021, 1:15 PMefemoney
08/14/2021, 1:20 PMErik
08/14/2021, 1:22 PMefemoney
08/14/2021, 1:32 PMinterface X { val flow: Flow ; fun refresh() }
is (necessarily) a better API.
For one at the callsite, it becomes x.flow.collect { ... }
vs x.collect { ... }
which may be less desirable depending on the concept x
is meant to represent.
Also for the same reason why (I imagine) StateFlow
is not defined as
interface StateFlow<T> { val flow: Flow ; val value: T}
what I want is a “flow that can be refreshed” and not an “entitity that has a flow and can be refreshed”Erik
08/14/2021, 1:34 PM