complete rework of states

This commit is contained in:
2024-05-12 21:34:17 +06:00
parent a1854b68d8
commit 4901a8844c
7 changed files with 80 additions and 108 deletions

View File

@@ -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)
}
}