使用以下demo_role | | {}
:
build.sbt
和这段代码:
name := "blah"
version := "1.0"
scalaVersion := "2.11.6"
libraryDependencies ++= Seq("io.reactivex" % "rxscala_2.11" % "0.24.1", "org.scalaj" %% "scalaj-http" % "1.1.4")
当我运行它时,所有打印的都是import rx.lang.scala.Observable
import scala.concurrent.duration._
import scala.language.postfixOps
object Main {
def main(args: Array[String]): Unit = {
println("Ready?")
val o = Observable.interval(200 millis).take(5)
o.subscribe(n => println(s"n = ${n}"))
}
}
;我完全看不到Ready?
。
我使用n = ...
运行;它是使用Scala 2.6.11和RxScala 0.24.1以及sbt 0.13构建的。有什么想法吗?
答案 0 :(得分:2)
问题是您的程序会在o
触发之前退出。请尝试以下代码:
import rx.lang.scala.Observable
import scala.concurrent.duration._
import scala.language.postfixOps
object Main {
def main(args: Array[String]): Unit = {
println("Ready?")
val o = Observable.interval(200 millis).take(5)
o.subscribe(n => println(s"n = ${n}"))
Thread.sleep(5000)
}
}
或者,您可以将Thread.sleep
替换为o.toBlocking.last
,o
在class Intermediate{
private static Type myObject=null;
public static void setIntermediate(Type ob){
myObject=ob;
}
public static String getValue(){
if(myObject!=null)
return myObject.getValue();
else
return ""; // <== always returning this value
}
}
终止之前无法返回。