All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonTest.flow.SafeFlowTest.kt Maven / Gradle / Ivy

There is a newer version: 1.9.0
Show newest version
/*
 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package kotlinx.coroutines.flow

import kotlinx.coroutines.*
import kotlin.test.*

class SafeFlowTest : TestBase() {

    @Test
    fun testEmissionsFromDifferentStateMachine() = runTest {
        val result = flow {
            emit1(1)
            emit2(2)
        }.onEach { yield() }.toList()
        assertEquals(listOf(1, 2), result)
        finish(3)
    }

    private suspend fun FlowCollector.emit1(expect: Int) {
        emit(expect)
        expect(expect)
    }

    private suspend fun FlowCollector.emit2(expect: Int) {
        emit(expect)
        expect(expect)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy