【问题标题】:KMM ios flow.combine throwing no event loop errorKMM ios flow.combine 抛出无事件循环错误
【发布时间】:2022-01-13 09:25:39
【问题描述】:
 suspend fun heyStackOverFlow(): Int {
    val flow1 = flow<Int> { 1 }
    val flow2 = flow<Int> { 2 }
    return flow1.combine(flow2) { f1, f2 -> f1 + f2 }.single()
}

我在 build.gradle 中使用它

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

我收到此错误

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

我尝试与其他问题的实际/预期调度员一起玩,但没有成功。 在 android 上完美运行,在 ios 上却不行。

【问题讨论】:

标签: ios flow kotlin-multiplatform kmm


【解决方案1】:

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

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

version {
    strictly("1.5.2-native-mt")
}

【讨论】:

    猜你喜欢
    • 2013-12-18
    • 2014-06-06
    • 2021-06-29
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 2013-12-21
    • 2016-07-19
    • 2020-02-19
    相关资源
    最近更新 更多