Joaquim Ley
07/23/2019, 3:03 PMkotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to MY_MODEL
- The way I apply these transformations is with the .map() operator
To make it more clear
Layer 1 - DB -> Flowable -> .map() -> asFlow() - âś…
Layer 2 - flow (from layer 1) -> .map() -> flow() - đź’Ą
I’ve been searching google and GitHub but it seems like this hasn’t been solved.
logs
Caused by: kotlinx.coroutines.JobCancellationException: Parent job is Cancelling; job=DispatchedCoroutine{Cancelled}@173d7e3
Caused by: java.lang.ClassCastException: kotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to MODEL_CLASS_HERE_
at CONTACT_REPOSITORY_CLASSl$fetchFlowContacts$1$1$invokeSuspend$$inlined$collect$1.emit(Collect.kt:73)
at kotlinx.coroutines.flow.FlowKt__TransformKt$map$$inlined$unsafeTransform$1$2.emit(Collect.kt:98)
at kotlinx.coroutines.reactive.flow.PublisherAsFlow.collect(PublisherAsFlow.kt:78)
at kotlinx.coroutines.reactive.flow.PublisherAsFlow$collect$1.invokeSuspend(Unknown Source:12)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)
-------------
A workaround is using the flatMapConcat()
instead of map()
and return a flowOf(someTransformation())
which feels a little dirty creating a new flow every-time data is emitted.
---------------
// Kotlin
versions.kotlin = “1.3.41”
versions.kotlin_coroutines = “1.2.1"
versions.kotlin_coroutines_reactive = “1.3.0-RC”
versions.kotlin_rx = “2.1.0"
Ran on AndroidJoaquim Ley
07/23/2019, 3:14 PMflow.transform { emit( /* transformation here */) }
works.tseisel
07/23/2019, 3:16 PMkotlinx-coroutines-core
and kotlinx-coroutines-reactive
?elizarov
07/23/2019, 3:38 PMJoaquim Ley
07/23/2019, 4:26 PMJoaquim Ley
07/23/2019, 4:30 PM