June 2017
Intermediate to advanced
400 pages
8h 44m
English
If there is blockingFirst(), it only makes sense to have blockingLast(). This will block and return the last value to be emitted from an Observable or Flowable operation. Of course, it will not return anything until onComplete() is called, so this is something you will want to avoid using with infinite sources.
Here, we assert that the last four-character string emitted from our operation is Zeta:
import io.reactivex.Observable; import org.junit.Test; import static org.junit.Assert.assertTrue; public class RxTest { @Test public void testLast() { Observable<String> source = Observable.just("Alpha", "Beta", "Gamma", "Delta", "Zeta"); String lastWithLengthFour = source.filter(s -> s.length() == 4) .blockingLast(); assertTrue(lastWithLengthFour.equals("Zeta")); ...Read now
Unlock full access