Flowable and Subscriber
Instead of Observer, Flowable uses Subscriber, which is backpressure compatible. However, if you use lambda expressions, then you will not notice any differences. So, why use Subscriber instead of Observer? Because Subscriber supports some extra operations and backpressure. For instance, it can convey how many items it wishes to receive as a message to upstream. Or rather, we can say while using Subscriber; you must specify how many items you want to receive (request) from upstream; if you don't specify it, you will not receive any emissions.
As we already mentioned, using lambda with Subscriber
is similar to Observe; this implementation will automatically request an unbounded number of emissions from the upstream. As with our last code, we didn't specify how many emissions we want, but it internally requested unbounded number of emissions, and that's why we received all the items emitted.
So, let's try replacing the previous program with a Subscriber
instance:
fun...