Travis Reitter
07/17/2023, 4:31 PMBroadcastChannel
. 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.Travis Reitter
07/17/2023, 4:34 PMprivate 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:
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 executorTravis Reitter
07/17/2023, 4:35 PMbindTo
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 didArkadii Ivanov
07/17/2023, 4:42 PMMutableSharedFlow<Input>(extraBufferCapacity = Int.MAX_VALUE)
.Travis Reitter
07/17/2023, 4:53 PMTravis Reitter
07/17/2023, 4:53 PMTravis Reitter
07/17/2023, 4:54 PMinput()
Arkadii Ivanov
07/17/2023, 5:07 PM