Created
July 25, 2020 21:28
-
-
Save mreram/eeb5197298b6f6d3ff2c240320759ba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.ExperimentalCoroutinesApi | |
import kotlinx.coroutines.FlowPreview | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.collect | |
import kotlinx.coroutines.launch | |
import kotlinx.coroutines.test.runBlockingTest | |
import org.junit.Test | |
class StateFlowTest2 { | |
@ExperimentalCoroutinesApi | |
companion object { | |
private val stateFlow = MutableStateFlow("initial value") | |
} | |
@FlowPreview | |
@ExperimentalCoroutinesApi | |
@Test | |
fun `send and receive a bullshit`() { | |
runBlockingTest { | |
val collectionJob = launch { | |
stateFlow.collect { | |
println(it) | |
} | |
} | |
launch { | |
delay(2000) | |
stateFlow.value = "heyyy" | |
collectionJob.cancel() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment