Understanding backpressure
The only problem with Observable
is when an Observer
cannot cope with the pace of an Observable
. An Observable
, by default, chains work by pushing items synchronously to the Observer
, one at a time. However, if the observer
has to perform some time-consuming computations, this may take longer than the interval of each item emission of Observable
. Confused? Let's consider this example:
fun main(args: Array<String>) { val observable = Observable.just(1,2,3,4,5,6,7,8,9)//(1) val subject = BehaviorSubject.create<Int>() subject.observeOn(Schedulers.computation())//(2) .subscribe({//(3) println("Subs 1 Received $it") runBlocking { delay(200) }//(4) }) subject.observeOn(Schedulers.computation())//(5) .subscribe({//(6) println("Subs 2 Received $it") }) observable.subscribe(subject)//(7) runBlocking...