2010-06-24 83 views
4

在C#中,你可以寫:
.NET的Task.Factory.StartNew的Scala等價物?

var alphaTask = Task.Factory.StartNew<alpha>(() => 
{ 
    return someWork(n);<br> 
}); 
// ... do some other work, and later get the result from the task<br> 
var res = alphaTask.Result; 

這個簡單的建築應該如何將看起來像斯卡拉?
謝謝。

+0

計算器上使用的注意事項。如果你覺得這個答案是正確的(也就是說),那麼你應該把它標記爲這樣 – 2010-07-04 20:52:04

回答

10

在斯卡拉2.8,最簡單的等同將

val future = Futures.future{ 
       someWork(n) 
      } 
// ... do some other work, and later get the result from the task 
val res = future();