Operator onBackpressureLatest()

This operator works exactly the same as the BackpressureStrategy.LATEST-it drops all the emissions keeping the latest one when the downstream is busy and can't keep up. When the downstream finishes the previous operation, it'll get the last emission just before it finished. Unfortunately, this doesn't provide any configurations; you will probably not need it.

Let's take a look at this code example:

    fun main(args: Array<String>) { 
      val source = Observable.range(1, 1000) 
      source.toFlowable(BackpressureStrategy.MISSING)//(1) 
        .onBackpressureLatest()//(2) 
        .map { MyItem13(it) } 
        .observeOn(Schedulers.io()) 
        .subscribe{ 
          print("-> $it;	") 
          runBlocking { delay(100) } 
        } 
        runBlocking { delay(600000) } 
    }  
    data class MyItem13 (val id:Int) { 
    init { 
      print("init $id;	") 
    } 
   } 

Here is the output:

As we can see, the Flowable dropped all emissions after 128, keeping only the last one (1,000).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.12.34