Thread
#multiplatform
    spierce7

    spierce7

    2 years ago
    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)
    .
    Caused by: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.flow.internal.SafeCollector@f506be8
    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)
                    }
                }
        )
    }
    Kris Wong

    Kris Wong

    2 years ago
    assuming you're not using the
    native-mt
    version of coroutines?
    spierce7

    spierce7

    2 years ago
    I am using the
    native-mt
    version of coroutines.
    Kris Wong

    Kris Wong

    2 years ago
    ah, then I am of no assistance 😛
    channels seemed to work for me. haven't tried flows