mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-10-05 15:19:27 +00:00
complete rework of states
This commit is contained in:
@@ -1,35 +1,33 @@
|
||||
import dev.inmo.micro_utils.coroutines.SpecialMutableStateFlow
|
||||
import dev.inmo.micro_utils.coroutines.asDeferred
|
||||
import dev.inmo.micro_utils.coroutines.subscribe
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SpecialMutableStateFlowTests {
|
||||
@Test
|
||||
fun simpleTest() {
|
||||
fun simpleTest() = runTest {
|
||||
val specialMutableStateFlow = SpecialMutableStateFlow(0)
|
||||
runTest {
|
||||
specialMutableStateFlow.value = 1
|
||||
specialMutableStateFlow.first { it == 1 }
|
||||
}
|
||||
specialMutableStateFlow.value = 1
|
||||
specialMutableStateFlow.first { it == 1 }
|
||||
assertEquals(1, specialMutableStateFlow.value)
|
||||
}
|
||||
@Test
|
||||
fun specialTest() {
|
||||
fun specialTest() = runTest {
|
||||
val specialMutableStateFlow = SpecialMutableStateFlow(0)
|
||||
runTest {
|
||||
lateinit var subscriberJob: Job
|
||||
subscriberJob = specialMutableStateFlow.subscribe(this) {
|
||||
when (it) {
|
||||
1 -> specialMutableStateFlow.value = 2
|
||||
2 -> subscriberJob.cancel()
|
||||
}
|
||||
lateinit var subscriberJob: Job
|
||||
subscriberJob = specialMutableStateFlow.subscribe(this) {
|
||||
when (it) {
|
||||
1 -> specialMutableStateFlow.value = 2
|
||||
2 -> subscriberJob.cancel()
|
||||
}
|
||||
specialMutableStateFlow.value = 1
|
||||
subscriberJob.join()
|
||||
}
|
||||
specialMutableStateFlow.value = 1
|
||||
subscriberJob.join()
|
||||
assertEquals(2, specialMutableStateFlow.value)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user