hi - I'm upgrading the dependencies in my project ...
# mvikotlin
t
hi - I'm upgrading the dependencies in my project and migrating to a newer version of Kotlin is requiring I move away from
BroadcastChannel
. The translation seems pretty simple but I'm having trouble getting it to work in my MVIKotlin-based project (and I believe this chunk of code is based closely on an older version of an MVIKotlin example). More details in the thread.
in a Component class, I'm moving from this:
Copy code
private val inputChannel = BroadcastChannel<Input>(Channel.BUFFERED)
val input: (Input) -> Unit = { inputChannel.trySend(it) }
init {
    bind(dependencies.lifecycle, BinderLifecycleMode.CREATE_DESTROY, mainContext) {
        inputChannel.asFlow().mapNotNull(inputToDetailIntent) bindTo recipeDetailStore
    }
}
to:
Copy code
private val inputFlow = MutableSharedFlow<Input>()
val input: (Input) -> Unit = { inputFlow.tryEmit(it) }
init {
    bind(dependencies.lifecycle, BinderLifecycleMode.CREATE_DESTROY, mainContext) {
        inputFlow.mapNotNull(inputToDetailIntent) bindTo recipeDetailStore
    }
}
With the former version, calls to
input()
get passed along as expected to the
recipeDetailStore
and handled in its executor. In the latter version, I confirmed they get passed to
inputFlow.tryEmit()
but they never reach the executor
any idea what I might be missing? It seems like
bindTo
would be unaffected by the change from
BroadcastChannel
to
MutableSharedFlow
and every tutorial I've found about this migration is pretty simple and just recommends the API translation I did
a
This looks like an issue with buffering. Try specifying
MutableSharedFlow<Input>(extraBufferCapacity = Int.MAX_VALUE)
.
t
perfect, that did it! Thank you!
I guess I misunderstood the way buffering would be treated in this case
I guess my approach could have only worked if the observer was set up before the initial call to
input()
a
Yes, the latter could work.