Skip to content

Commit 0eda66f

Browse files
committed
Kotlin 2.0.0
1 parent 1c5dc45 commit 0eda66f

File tree

1 file changed

+13
-3
lines changed
  • src/main/kotlin/com/hoc081098/kotlin_playground/solivagant

1 file changed

+13
-3
lines changed

src/main/kotlin/com/hoc081098/kotlin_playground/solivagant/main.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ import androidx.compose.ui.window.Window
2525
import androidx.compose.ui.window.application
2626
import com.hoc081098.channeleventbus.ChannelEvent
2727
import com.hoc081098.channeleventbus.ChannelEventBus
28+
import com.hoc081098.channeleventbus.ChannelEventBusException
2829
import com.hoc081098.channeleventbus.ChannelEventKey
2930
import com.hoc081098.channeleventbus.OptionWhenSendingToBusDoesNotExist
3031
import com.hoc081098.channeleventbus.ValidationBeforeClosing
32+
import com.hoc081098.flowext.FlowExtPreview
33+
import com.hoc081098.flowext.catchAndResume
3134
import com.hoc081098.kmp.viewmodel.Closeable
3235
import com.hoc081098.solivagant.lifecycle.LocalLifecycleOwner
3336
import com.hoc081098.solivagant.lifecycle.compose.collectAsStateWithLifecycle
@@ -45,6 +48,7 @@ import com.hoc081098.solivagant.navigation.rememberWindowLifecycleOwner
4548
import kotlin.LazyThreadSafetyMode.NONE
4649
import kotlin.random.Random
4750
import kotlinx.collections.immutable.persistentSetOf
51+
import kotlinx.coroutines.flow.emptyFlow
4852

4953
@OptIn(ExperimentalSolivagantApi::class)
5054
fun main() {
@@ -88,12 +92,18 @@ fun MyApp(modifier: Modifier = Modifier) {
8892

8993
@Immutable
9094
data object FirstRoute : NavRoot {
95+
@OptIn(FlowExtPreview::class)
9196
@JvmStatic
9297
@Stable
9398
val Destination = ScreenDestination<FirstRoute> { route, modifier ->
94-
val result by EventBus
95-
.receiveAsFlow(SecondResultToFirst)
96-
.collectAsStateWithLifecycle(null)
99+
val result by remember {
100+
EventBus
101+
.receiveAsFlow(SecondResultToFirst)
102+
.catchAndResume {
103+
if (it is ChannelEventBusException.FlowAlreadyCollected) emptyFlow()
104+
else throw it
105+
}
106+
}.collectAsStateWithLifecycle(null)
97107

98108
rememberCloseableOnRoute(route) {
99109
Closeable {

0 commit comments

Comments
 (0)