How to run filter, mapand flatMapon Observableusing multiple threads:
def withDelay[T](delay: Duration)(t: => T) = {
Thread.sleep(delay.toMillis)
t
}
Observable
.interval(500 millisecond)
.filter(x => {
withDelay(1 second) { x % 2 == 0 }
})
.map(x => {
withDelay(1 second) { x * x }
}).subscribe(println(_))
The goal is to simultaneously perform filtering and conversion operations using multiple threads.
source
share