https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

spierce7

03/31/2020, 8:47 PM
I’m seeing an exception working with Flow across threads in Kotlin/native using the
native-mt
version of kotlinx.coroutines. I’ve been stuck on this for a while now. Can anyone point me in the right direction for how to fix this? It’s throwing an error on the
emit(defaultValue)
.
Copy code
Caused by: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.internal.SafeCollector@f506be8
Copy code
return flow {
    var isEmpty = true

    emitAll(
        abTestRepository.getExperiments(
            appName = appName,
            userIdentifier = userIdentifier,
            experiments = experiments,
            mode = mode
        )
            .onEach { isEmpty = false }
            .onCompletion {
                if (isEmpty) {
                    val defaultData = RallyAbTest.data.experiments.map {
                        ExperimentGroup(
                            name = it.name,
                            value = it.defaultGroup
                        )
                    }.freeze()

                    emit(defaultData)
                }
            }
    )
}
k

Kris Wong

03/31/2020, 8:56 PM
assuming you're not using the
native-mt
version of coroutines?
s

spierce7

03/31/2020, 8:58 PM
I am using the
native-mt
version of coroutines.
k

Kris Wong

03/31/2020, 9:00 PM
ah, then I am of no assistance 😛
channels seemed to work for me. haven't tried flows