https://kotlinlang.org logo
Title
d

dariuszbacinski

11/07/2019, 8:36 AM
@Test
    fun coroutineTest() {
        runBlocking {
            flowOf("any").map {
                val result = ioFunction() //crash java.lang.ClassCastException: kotlin.coroutines.intrinsics.CoroutineSingletons cannot be cast to java.util.Map
                result
            }.collect { result ->
                Log.v("$result")
            }
        }
    }

    suspend fun ioFunction(): Map<Long, Int> = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
        mapOf(1L to 4)
    }
how can is use suspend function in when mapping Flow? above code crashes, but it works when I remove suspend function and use normal blocking function
✔️ 1
should I use different operator then map?
o

octylFractal

11/07/2019, 8:38 AM
that looks like a bug in the compiler, should be fine code except you should use
delay
and not sleep
the CCE would be coming from the
COROUTINE_SUSPENDED
internal value being leaked
d

dariuszbacinski

11/07/2019, 8:39 AM
removed sleep it doesn't matter here
I am using kotlin_version = '1.3.21'
o

octylFractal

11/07/2019, 8:45 AM
yes, probably
d

dariuszbacinski

11/07/2019, 8:55 AM
It works with 1.3.50, thank you ✔️