Multicasting with operators

To see how multicasting works within a chain of operators, we are going to use Observable.range() and then map each emission to a random integer. Since these random values will be non-deterministic and different for each subscription, it will provide a good way to see whether our multicasting is working because each Observer should receive the same value.

Let's start with emitting the numbers 1 through 3 and map each one to a random integer between 0 and 100,000. If we have two observers, we can expect different integers for each one. Note that your output will be different to that presented due to the random nature of number generation. Just note that both observers are receiving different random integers:

import ...

Get Learning RxJava - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.