June 2018
Intermediate to advanced
310 pages
6h 32m
English
In all previous examples, we emitted data using Observable or subject, which also extends Observable, and it worked out pretty well.
But our listeners weren't doing much. What if they were to do something more substantial?
Let's see the following example. We'll produce a lot of unique strings:
val source = Observable.create<String> { var startProducing = System.currentTimeMillis() for (i in 1..10_000_000) { it.onNext(UUID.randomUUID().toString()) if (i % 100_000 == 0) { println("Produced $i events in ${System.currentTimeMillis() - startProducing}ms") startProducing = System.currentTimeMillis() } } latch.countDown()}
We're using CountDownLatch so the main thread will be able to wait until we finish. In addition, we're also printing ...
Read now
Unlock full access