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() events to pass each time an item is requested from the upstream.
Before you use Flowable.generate(), consider making your source...