在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中会是什么样子? 谢谢。
答案 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();