https://kotlinlang.org logo
#coroutines
Title
# coroutines
p

Patrick Steiger

12/07/2023, 1:25 PM
Supposing I am building a flow operator that uses channel flow, and I know the upstream flow is also a channel flow, can I make them fuse? AFAIK this won’t fuse:
Copy code
channelFlow {
  channelFlow {
    send(1)
  }.collect { send(it) }
}
… to be clear, I don’t think not fusing in this case is a problem since it’s just a perf optimization as far as I understand. Just curious if there’s a publicly exposed way (since FusibleFlow, ChannelFlowOperator, etc are internal)
👀 1
☝️ 1
d

Daniel Pitts

12/07/2023, 10:44 PM
It doesn't look like there is a way to do that. I don't even think it's an optimization really. The thing that "fusing" does is combine the configuration of buffer/context of the flow.
Though it seems like this would be better structured as
Copy code
channelFlow {
   send(1)
}.map { it }
p

Patrick Steiger

12/08/2023, 1:02 AM
Example is contrived, actual code needs to populate the downstream channel from multiple coroutines, where 1 of them is collecting from upstream channel flow and sending to downstream channel flow
Thanks for answering though, I think it’s indeed not possible
Also you’re right fusing is not (just?) for optimization purposes, since fusing has its own logic for somehow combines the configs (either overriding, or summing, etc