@@ -25,9 +25,12 @@ import androidx.compose.ui.window.Window
25
25
import androidx.compose.ui.window.application
26
26
import com.hoc081098.channeleventbus.ChannelEvent
27
27
import com.hoc081098.channeleventbus.ChannelEventBus
28
+ import com.hoc081098.channeleventbus.ChannelEventBusException
28
29
import com.hoc081098.channeleventbus.ChannelEventKey
29
30
import com.hoc081098.channeleventbus.OptionWhenSendingToBusDoesNotExist
30
31
import com.hoc081098.channeleventbus.ValidationBeforeClosing
32
+ import com.hoc081098.flowext.FlowExtPreview
33
+ import com.hoc081098.flowext.catchAndResume
31
34
import com.hoc081098.kmp.viewmodel.Closeable
32
35
import com.hoc081098.solivagant.lifecycle.LocalLifecycleOwner
33
36
import com.hoc081098.solivagant.lifecycle.compose.collectAsStateWithLifecycle
@@ -45,6 +48,7 @@ import com.hoc081098.solivagant.navigation.rememberWindowLifecycleOwner
45
48
import kotlin.LazyThreadSafetyMode.NONE
46
49
import kotlin.random.Random
47
50
import kotlinx.collections.immutable.persistentSetOf
51
+ import kotlinx.coroutines.flow.emptyFlow
48
52
49
53
@OptIn(ExperimentalSolivagantApi ::class )
50
54
fun main () {
@@ -88,12 +92,18 @@ fun MyApp(modifier: Modifier = Modifier) {
88
92
89
93
@Immutable
90
94
data object FirstRoute : NavRoot {
95
+ @OptIn(FlowExtPreview ::class )
91
96
@JvmStatic
92
97
@Stable
93
98
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 )
97
107
98
108
rememberCloseableOnRoute(route) {
99
109
Closeable {
0 commit comments