rx-scala

Combining groupBy and flatMap(maxConcurrent, …) in RxJava/RxScala

允我心安 提交于 2020-01-17 07:29:49
问题 I have incoming processing requests, of which I want do not want too many processing concurrently due to depleting shared resources. I also would prefer requests which share some unique key to not be executed concurrently: def process(request: Request): Observable[Answer] = ??? requestsStream .groupBy(request => request.key) .flatMap(maxConcurrentProcessing, { case (key, requestsForKey) => requestsForKey .flatMap(1, process) }) However, the above doesn't work because the observable per key

Why doesn't this execute the function given for RxScala's doOnSubscribe function?

馋奶兔 提交于 2020-01-06 14:41:30
问题 val x: Observable[Int] = Observable.just(1).doOnSubscribe(() => println(s"subscribed")) val y = x.subscribe(t => println(s"got item: $t")) println("all done") I would have thought this code would print subscribed got item: 1 all done But it doesn't print the initial "subscribed". 回答1: The signature of doOnSubscribe is: def doOnSubscribe(onSubscribe: => Unit): Observable[T] That is, it takes a by-name argument. So you have to use it as follows: Observable.just(1).doOnSubscribe(println(s

Why doesn't this execute the function given for RxScala's doOnSubscribe function?

℡╲_俬逩灬. 提交于 2020-01-06 14:41:11
问题 val x: Observable[Int] = Observable.just(1).doOnSubscribe(() => println(s"subscribed")) val y = x.subscribe(t => println(s"got item: $t")) println("all done") I would have thought this code would print subscribed got item: 1 all done But it doesn't print the initial "subscribed". 回答1: The signature of doOnSubscribe is: def doOnSubscribe(onSubscribe: => Unit): Observable[T] That is, it takes a by-name argument. So you have to use it as follows: Observable.just(1).doOnSubscribe(println(s

Converting RxJava to RxScala

感情迁移 提交于 2019-12-23 12:53:17
问题 Is there a way to use both RxJava and RxScala in one project? import rx.lang.scala.{Observable => ScalaObservable} import rx.{Observable => JavaObservable} We have a module written in Java that is using the JavaObservable ( RxJava ). And then we have a Scala module that is supposed to use the Java module but is written in Scala. Are there convenient methods to transform these into the other? 回答1: Yes, this is possible by using the conversion functions such as toJavaObservable ,

RxScala: How to keep the thread doing Observable.interval alive?

假如想象 提交于 2019-12-11 10:56:01
问题 I am trying to write a simple RxScala program: import rx.lang.scala.Observable import scala.concurrent.duration.DurationInt import scala.language.{implicitConversions, postfixOps} object Main { def main(args: Array[String]): Unit = { val o = Observable.interval(1 second) o.subscribe(println(_)) } } When I run this program, I do not see anything printed out. I suspect that this is because that thread producing the numbers in Observable.interval dies. I noticed a call to waitFor(o) in the