We know that channelFlow can do what flow can't e.g.
- Retrieve value from a concurrently run coroutine
- Can use a non-suspending way i.e. trySendto send data
It looks like it is more powerful than flow. I wonder
- if there's anything where flowcan do but not inchannelFlow, or
- if there's anything flowis preferred overchannelFlow(e.g. in terms of efficiency or performance?)?
The reason I ask is, I want to see if we can just use channelFlow for everything instead, or what's the scenario we should use flow instead?
 
                        
I don't have an authoritative source, but there are two things I notice by browsing the documentation and source code.
flowis lighter-weight since it doesn't have the thread-safety features of a Channel.channelFlowis buffered, but you can modify the buffer or make itRENDEVOUSwith thebuffer()operator.flowis not buffered, but you can use thebuffer()operator, which wraps it in a Channel-based flow.Personally,
flowis my default choice for simplicity, unless the features of a Channel are needed. Frequently my cold flows are shared into a SharedFlow somewhere downstream, so I tend to avoid messing with buffering in the upstream. It all depends on where buffering behavior is best encapsulated on a case-by-case basis, though.