我試圖重現新斯卡拉2.10 futures feature的例子。 我使用的代碼是:可能的錯誤在斯卡拉2.10:期貨市場不運行
import scala.concurrent.Future
import scala.concurrent.future
object Test {
def main(args: Array[String]) {
println("Test print before future")
val s = "Hello"
val f = future {s + " future!"}
f onSuccess {case v => println(v)}
println("Test print after future")
}
}
除了打印:
Test print before future
Hello future!
Test print after future
它只是打印:
Test print before future
Test print after future
爲什麼我有這樣的行爲的任何想法?我的版本的scala編譯器是2.10.0-20120507。
你知道嗎?我想過這個問題,因爲在處理goroutines時,其原因完全相同:在關閉主塊之前使用通道等待goroutines發送的消息。 –
@ Heather是否有可能等待多個未來? – 66CLSjY