How to run filter
, map
and flatMap
on Observable
using 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 run filtering and transformation operations concurrently using multiple threads.