Here's a thought experiment I've been having while...
# flow
g
Here's a thought experiment I've been having while writing some code. Consider a batch of flow singles that each emit a result of a network request. These flows are organized (as part of other objects) into a indeterminate unbounded tree structure. Each flow is an operation to update the given object that it's part of, hence why it's a single. So it's sort of complex to manage the execution load. I don't want to just execute a thousand flows at once the moment something subscribes to them, since that will obviously overwhelm an API limit. Coroutines have channels/mutex depending on if you care about execution order. Is there something similar for Flows where you can subscribe to them, but the actual execution order is limited and controlled by some sort of lock? That way you can guarantee that only 1 or 2 are running in parallel. I do get that I could just solve the problem by using a coroutine and a mutex, but I wanted to see if I could accomplish this with Flows just for the thought experiment & because the resulting API in the UI is nicer and lets you abstract more away from the UI.
c
By “singles” do you mean a flow that only emits once?
e
Copy code
flowOf(flow1, flow2, flow3, ...).flattenMerge(concurrency = 2)
will subscribe to at most 2 of the flows at a time