Please help. I was trying to do:
2sec 2sec 2sec
------[A]------[B]------[C]------...----------------> InitailFlow
\ | |
\ drop drop
\
5sec \ 5sec 5sec
----------[1]---------[2]---------[3]-----|> AnotherFlow
result: [A1, A2, A3]
So I have InitailFlow which emits a short amount of time (2 seconds) which is then transformed to AnotherFlow which takes longer to finish (15 seconds in total)... I would like to drop the other incoming items emitted by the InitialFlow while AnotherFlow isn't finished...
I've tried:
flow{
delay(2000)
emit("A")
delay(2000)
emit("B")
delay(2000)
emit("C")
}.buffer(0, BufferOverflow.DROP_LATEST)
.onEach {
println("Event for $it")
}
.flatMapConcat {
flow {
delay(5000)
emit("${it}1")
delay(5000)
emit("${it}2")
delay(5000)
emit("${it}3")
}
}
.onEach {
println(it)
}
.launchIn(scope)
But for some reason this is the result:
Event for A
A1
A2
A3
Event for B
B1
B2
B3
It still process Event B for some reason even when I have a .buffer(0, BufferOverflow.DROP_LATEST).
Why does it still process Event B?
Is there a way to do this? I expect the output to be only:
Event for A
A1
A2
A3
Thanks in advance.