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