Getting the last Item - blockingLast

We have blockingFirst, so it's quite obvious that we would have blockingLast. As expected, it gets you the last emitted item while blocking the thread until the source emits it. The following is the code example:

    @Test 
    fun `test with blockingLast`() { 
      val observable = listOf(2,10,5,6,9,8,7,1,4,3).toObservable() 
               .sorted() 
 
      val firstItem = observable.blockingLast() 
      assertEquals(10,firstItem) 
   } 

As we are expecting the last emitted item, we are checking equality with 10.

Following is the screenshot of the testing result:

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.