Kotlinx.coroutines: native-mt: Flow.combine does not work in another thread

Created on 17 Jan 2020  路  3Comments  路  Source: Kotlin/kotlinx.coroutines

See https://github.com/Kotlin/kotlinx.coroutines/pull/1648#issuecomment-574259404 by @Thomas-Vos

I've a bit minimized it to this test:

    @Test
    fun testFlowCombine() = runTest {
        withContext(Dispatchers.Default) {
            val flow = flowOf(1)
            val combo = combine(flow, flow) { a, b -> a + b }
            assertEquals(2, combo.first())
        }
    }

It crashes due to freezing on coroutine's state machine inside implementation of combine.

flow native

Most helpful comment

I've finally managed to fix it. Pushed to native-mt branch.

All 3 comments

This also applies to other operators like flatMapConcat(). That's a bit problematic with the approach described in KaMPKit (recently promoted on the Jetbrains blog, see init in BreedModel.kt):

       mainScope.launch {
            dbHelper.selectAllItems().asFlow()
                .flatMapConcat { dbHelper.selectAllItems().asFlow() } // for testing
                .map { q ->
                    val itemList = q.executeAsList()
                    ItemDataSummary(itemList.maxBy { it.name.length }, itemList)
                }
        }

Doesn't happen on Android, only iOS.

I've finally managed to fix it. Pushed to native-mt branch.

Fixed in 1.3.9-native-mt

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Leftwitch picture Leftwitch  路  3Comments

mhernand40 picture mhernand40  路  3Comments

jaozinfs picture jaozinfs  路  3Comments

sky87 picture sky87  路  3Comments

IgorKey picture IgorKey  路  3Comments