Scala相当于.NET的Task.Factory.StartNew?

时间:2010-06-24 01:03:39

标签: scala task

在C#中你可以写:

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;

这种简单的结构在Scala中会是什么样子? 谢谢。

1 个答案:

答案 0 :(得分:10)

在Scala 2.8中,最简单的等价物是

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