尽管使用awaitAll,Scala期货还没有输出到屏幕?

时间:2015-08-09 08:41:25

标签: scala

我使用的是旧版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

知道出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

您的算法很好,但是,如果您没有直接评估(例如在REPL或工作表中),则需要定义主方法。

以下内容可行:

import scala.actors.Futures._

object Main {

    def bubbles = {
        //Your algorithm here
    }

    def main(args: Array[String]) {
        Main.bubbles
    }
}