Using Flowable.generate()
Despite a lot of the content that has been covered so far in this chapter, we have not yet demonstrated the optimal approach to apply backpressure to a source. Although the standard Flowable factories and operators automatically handle the backpressure, the onBackPressureXXX() operators, while quick and effective for some cases, just cache or drop emissions, which is not always desirable. It would be better to force the source to slow down as needed in the first place.
Thankfully, Flowable.generate() exists to help create backpressure, respecting sources at a nicely abstracted level. It accepts a Consumer<Emitter<T>>, much like Flowable.create(), but uses a lambda to specify which onNext(), onComplete(), and onError() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access