The problem is that it's unclear what to do with items emitted between
flow.replayCache
and
.collect
calls
d
dimsuz
01/13/2022, 1:58 PM
Nice, thank you!
I can do without collect even:
Copy code
fun get(replayLast) = flow.drop(if (replayLast) 0 else flow.replayCache.size))
b
bezrukov
01/13/2022, 2:51 PM
you're returning a cold flow (what if a caller will start collecting it after a few more emits?) so you have to wrap it to flow builder
d
dimsuz
01/13/2022, 3:45 PM
yep, cold flow is my intention here, so it's ok.
b
bezrukov
01/13/2022, 8:40 PM
No, I mean replayCache.size may change between calling get function and collect:
Copy code
// Nothing were emitted to `flow` yet
val cold = get(replayLatest = false) // you made a cold flow with drop(0)
flow.emit(1)
cold.collect { } // you will receive 1