@@ -10,7 +10,6 @@ import androidx.lifecycle.DefaultLifecycleObserver
1010import androidx.lifecycle.Lifecycle
1111import androidx.lifecycle.LifecycleOwner
1212import androidx.lifecycle.ProcessLifecycleOwner
13- import kotlinx.coroutines.CancellationException
1413import kotlinx.coroutines.CoroutineScope
1514import kotlinx.coroutines.MainScope
1615import kotlinx.coroutines.channels.Channel
@@ -20,7 +19,6 @@ import kotlinx.coroutines.flow.Flow
2019import kotlinx.coroutines.flow.buffer
2120import kotlinx.coroutines.flow.channelFlow
2221import kotlinx.coroutines.launch
23- import kotlinx.coroutines.runBlocking
2422import mozilla.components.lib.state.Action
2523import mozilla.components.lib.state.Observer
2624import mozilla.components.lib.state.State
@@ -119,15 +117,7 @@ fun <S : State, A : Action> Store<S, A>.channel(
119117 val channel = Channel <S >(Channel .CONFLATED )
120118
121119 val subscription = observeManually { state ->
122- runBlocking {
123- try {
124- channel.send(state)
125- } catch (e: CancellationException ) {
126- // It's possible for this channel to have been closed concurrently before
127- // we had a chance to unsubscribe. In this case we can just ignore this
128- // one subscription and keep going.
129- }
130- }
120+ channel.trySend(state)
131121 }
132122
133123 subscription.binding = SubscriptionLifecycleBinding (owner, subscription).apply {
@@ -171,15 +161,7 @@ fun <S : State, A : Action> Store<S, A>.flow(
171161 owner?.lifecycle?.removeObserver(ownerDestroyedObserver)
172162
173163 val subscription = observeManually { state ->
174- runBlocking {
175- try {
176- send(state)
177- } catch (e: CancellationException ) {
178- // It's possible for this channel to have been closed concurrently before
179- // we had a chance to unsubscribe. In this case we can just ignore this
180- // one subscription and keep going.
181- }
182- }
164+ trySend(state)
183165 }
184166
185167 if (owner == null ) {
0 commit comments