Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala equivalent of .NET's Task.Factory.StartNew?

Tags:

scala

task

In C# you can write:

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;

How would this simple construction look like in Scala?
Thank you.

like image 715
John Avatar asked Dec 29 '22 12:12

John


1 Answers

In Scala 2.8, the simplest equivalent would be

val future = Futures.future{
                someWork(n)
           }
// ... do some other work, and later get the result from the task
val res = future();  
like image 124
Dave Griffith Avatar answered Jan 15 '23 05:01

Dave Griffith