I have a list of tasks and i before running them i...
# coroutines
c
I have a list of tasks and i before running them i sort them by an order field. (order 0 runs first, then order 1, etc). the generating of that list takes some and i want to start executing before the list is finished so could use a flow for it. but sorting would require the list to be complete, so instead i want a flow that first emits all the entries with order = 0, then when the flow is finished i want to sort the rest of the elements and execute those. is there a way to do that with flows?
j
Why not use a min heap?
c
How would that work?
j
it's nothing specific to flows. But a min heap will guarantee that the top of the heap will be an order with the minimum order # so far. And you add orders as they come in.
A min heap is pretty straightforward to implement - lots of examples online - if you choose to go in that direction.
c
I think it has nothing to do with what i want. I want a replicate operator. https://github.com/Kotlin/kotlinx.coroutines/issues/1086#issuecomment-585195388 a shared flow that also ends.