How to use multiple threads to execute map, filter and flatmap in rxscala / Java?

How to use multiple threads to run filter, map and flatmap on observable:

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 use multiple threads to run filtering and transformation operations at the same time

Solution

Yo can use async. On each operation toAsync().

It is located on the package rxjava async

Documentation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>