https://kotlinlang.org logo
Title
c

christophsturm

06/03/2021, 12:25 PM
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

julian

06/03/2021, 2:19 PM
Why not use a min heap?
c

christophsturm

06/03/2021, 4:04 PM
How would that work?
j

julian

06/03/2021, 6:04 PM
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

christophsturm

06/04/2021, 8:57 AM
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.