下面的代碼沒有預料到什麼。Scala未來 - 初學者查詢
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
object UseFuture extends App
{
implicit val ec = ExecutionContext.global
Future(println { "This should be run in another thread" })
println("Test")
}
但我沒能看到未來的輸出。
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
object UseFuture extends App
{
implicit val ec = ExecutionContext.global
Future(println { "This should be run in another thread" })
}
一個快速的解釋?
也許你未來之前完成項目被定?嘗試在最後添加一個'Thread.sleep'。 – Thilo