Slightly different question from yesterday. I have a flow that can only be consumed once(a grpc stream). I need to pull the first element off like with
first
but I don't want to close the flow. I need the rest of the elements to be still available.
val requests: Flow<Request>
val foo = requests.toList()
val targetServer = doSomethingWithFirstElement(foo.first())
targetServer.makeReuqest(foo.asFlow())
, and another time with a filter to omit the first item.
t
taer
02/02/2021, 10:31 PM
I tried that. The shareIn got greedy and drained the flow. my second call the flow only contained the last element. I had set it up w/ a replay of one.
taer
02/02/2021, 10:37 PM
putting some logging around it to see what's going on. I kinda want that buffer(0) behavior with one replay
t
Tijl
02/02/2021, 10:39 PM
if you don’t want to buffer it then what you want is very specific, so you should just collect yourself (once) and save the first element for whatever way you want to get it, and then emit the other elements to a new flow, then you can suspend again on your emit(inside your collect) with the desired behaviour (no buffer as you just said)