Hello community, hope you all doing well.
I am getting compilation error by this code. This code written in BaseFragment, and I am trying to use it in the child.
The error I am getting is:
e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'collectInMainBy' into
So why it can’t be inlined?
inline fun <reified T> Flow<T>.collectInMainBy(
crossinline onCollect: suspend (T) -> Unit,
crossinline onFailure: suspend (Throwable) -> Unit = { Timber.e(it, tag) }
) {
onEachCatching(onCollect, onFailure).launchInMain(lifecycleScope)
}
inline fun <reified T> Flow<T>.onEachCatching(
crossinline onEach: suspend (T) -> Unit,
crossinline onFailure: suspend (Throwable) -> Unit
) : Flow<T> {
return onEach {
onEach(it)
}.catch {
onFailure(it)
}
}
fun <T> Flow<T>.launchInMain(scope: CoroutineScope): Job = scope.launch(Dispatchers.Main) {
collect()
}
Call side:
buttonProceed.clicks().collectInMainBy(
onCollect = { viewModel.proceedButtonClicked() }
)