In RxJava 2 Flowable there are different backpressure strategies, among them the most interesting are:

LATEST

BUFFER

DROP

which are respected throughout whole Rx chain.

In Kotlin there is Flow, which declares that it has backpressure support out-of-the-box. I was able to make Flow to have BUFFER and LATEST strategies by using the following:

For BUFFER:

observeFlow() .buffer(10) .collect { ... }

With LATEST:

observeFlow() .conflate() .collect { ... }

Which is just shortcut on that same buffer operator.

But I was not able to find anything that can work same as DROP. In short DROP will drop any value which comes in the stream when previous value hasn't been processed yet. And with Flow I even not sure that it is possible at all.

Considering the case:

observeFlow() .backpressureDrop() // non-existent operator, just for illustrative purposes .map { ... } .flatMapMerge { ... } .collect { ... }

So backpressureDrop should respect any work which is done below in the stream, while that operator don't know anything about what is happening below (without explicit callback from the bottom - like "request" method in RxJava Subscriber). Therefore it seems not that possible. And that operator should not pass through any event before previous item was collected.

Is there any ready operator, which I miss, or is there a straightforward way to implement something like this with existing API?