You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a setup where controllers are kept in a higher-level node and then passed down to children that are inside a pager. With the 3.0.0 version, the code crashes when a controller is used again in the capturable() modifier due to attempting to consume a channel as a flow multiple times.
I believe it is due to this change: 931937c. It can be fixed by making the flow hot with .receiveAsFlow() instead as the channel wouldn't be subscribed to multiple times. And #202 is still fixed. Though, .receiveAsFlow() uses a fan-out algorithm so simultaneous .captureable() modifiers with the same controller would not receive requests. But at this point it is a misuse of APIs.
I have a a working fix (MiSikora@af82176) with a solution using .receiveAsFlow(). Let me know If I should make a PR.
Here's a simple reproducer. Open the app with this component added, swipe to the 2nd page, and go back to the 1st one.
java.lang.IllegalStateException: ReceiveChannel.consumeAsFlow can be collected just once
at kotlinx.coroutines.flow.ChannelAsFlow.markConsumed(Channels.kt:101)
at kotlinx.coroutines.flow.ChannelAsFlow.collect(Channels.kt:124)
at kotlinx.coroutines.flow.FlowKt__CollectKt.emitAll(Collect.kt:105)
at kotlinx.coroutines.flow.FlowKt.emitAll(Unknown Source:1)
at dev.shreyaspatil.capturable.CapturableModifierNode$observeCaptureRequestsAndServe$$inlined$flatMapLatest$1.invokeSuspend(Merge.kt:189)
at dev.shreyaspatil.capturable.CapturableModifierNode$observeCaptureRequestsAndServe$$inlined$flatMapLatest$1.invoke(Unknown Source:11)
at dev.shreyaspatil.capturable.CapturableModifierNode$observeCaptureRequestsAndServe$$inlined$flatMapLatest$1.invoke(Unknown Source:4)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invokeSuspend(Merge.kt:30)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invoke(Unknown Source:8)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1$2.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:27)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:90)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:43)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$1.emit(Merge.kt:29)
at kotlinx.coroutines.flow.StateFlowImpl.collect(StateFlow.kt:396)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invokeSuspend(Merge.kt:23)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invoke(Unknown Source:8)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:61)
at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:261)
at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest.flowCollect(Merge.kt:21)
at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo$suspendImpl(ChannelFlow.kt:153)
at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo(Unknown Source:0)
at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:56)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:68)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1404)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
at android.view.Choreographer.doFrame(Choreographer.java:941)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8592)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
The text was updated successfully, but these errors were encountered:
I have a setup where controllers are kept in a higher-level node and then passed down to children that are inside a pager. With the
3.0.0
version, the code crashes when a controller is used again in thecapturable()
modifier due to attempting to consume a channel as a flow multiple times.I believe it is due to this change: 931937c. It can be fixed by making the flow hot with
.receiveAsFlow()
instead as the channel wouldn't be subscribed to multiple times. And #202 is still fixed. Though,.receiveAsFlow()
uses a fan-out algorithm so simultaneous.captureable()
modifiers with the same controller would not receive requests. But at this point it is a misuse of APIs.I have a a working fix (MiSikora@af82176) with a solution using
.receiveAsFlow()
. Let me know If I should make a PR.Here's a simple reproducer. Open the app with this component added, swipe to the 2nd page, and go back to the 1st one.
The text was updated successfully, but these errors were encountered: