我使用的是旧版scala 2.7.6
以下代码编译并运行。但是尽管使用了awaitAll()
import scala.actors.Futures._
def bubbles = {
val bubbles = for (i <- 1 to 20) yield {
future {
Thread.sleep(100)
println("pop " + i)
"pop " + i
}
}
awaitAll(30000, bubbles:_*) foreach println _
}
bubbles
知道出了什么问题吗?
答案 0 :(得分:0)
您的算法很好,但是,如果您没有直接评估(例如在REPL或工作表中),则需要定义主方法。
以下内容可行:
import scala.actors.Futures._
object Main {
def bubbles = {
//Your algorithm here
}
def main(args: Array[String]) {
Main.bubbles
}
}