June 2017
Intermediate to advanced
400 pages
8h 44m
English
It probably is no surprise that since window() is similar to buffer() (other than that it emits Observables instead of connections), you can also use another Observable as boundary.
Here, we use an Observable.interval() emitting every 1 second to serve as the boundary on an Observable emitting every 300 milliseconds. We leverage each emitted Observable to concatenate emissions into concatenated strings:
import io.reactivex.Observable;import java.util.concurrent.TimeUnit;public class Launcher { public static void main(String[] args) { Observable<Long> cutOffs = Observable.interval(1, TimeUnit.SECONDS); Observable.interval(300, TimeUnit.MILLISECONDS) .map(i -> (i + 1) * 300) // map to elapsed time .window(cutOffs)Read now
Unlock full access