I am relatively new to RxJava, and I have been playing around with operators for a while.
I saw this small example that emits items after short intervals (1s):
Observable<String> data = Observable.just("one", "two", "three", "four", "five");
Observable.zip(data, Observable.interval(1, TimeUnit.SECONDS), (d, t) -> {
return d + " " + t;
}).toBlocking().forEach(System.out::println);
This works, but when I remove toBlocking()
that turns the source into a BlockingObservable, the program executes and ends with no output.
I usually look at the marble diagrams to understand things properly: http://reactivex.io/documentation/operators/zip.html
In the last sentence it says: It will only emit as many items as the number of items emitted by the source Observable that emits the fewest items.
Does that mean, the data
Observable emits all items in less than 1 second and ends before printing the first two items from each Observable? Because each Observable is asynchronous by itself?
I need a clear understanding of what's happening, and if there are other ways to deal with similar cases. Anyone?