0
 suspend fun heyStackOverFlow(): Int {
    val flow1 = flow<Int> { 1 }
    val flow2 = flow<Int> { 2 }
    return flow1.combine(flow2) { f1, f2 -> f1 + f2 }.single()
}

I use this in build.gradle

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt")
            ...
        }
    }

I get this error

 kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.

I've tried playing around with actual / expected dispatchers from other questions but no success. On android this works perfectly, on ios it doesn't.

4

1 回答 1

1

您可以检查gradle dependencies某些第 3 方可能会引入非本地 mt 版本的协程。

如果是这种情况,您可以按照 Philip 的建议强制使用 native-mt 版本:

version {
    strictly("1.5.2-native-mt")
}
于 2021-12-08T15:00:03.753 回答