2011-07-06 68 views

回答

2

並行異步執行一個任務,只要使用Actor.actor方法:

import scala.actors.Actor._ 

actor { 
    // code here is excuted asynchronously 
} 

執行任務,並等待結果,利用期貨:

import scala.actors.Futures.future 

val f = future { 
    // code here is excuted asynchronously 
    // last expression is returned 
} 
//... other code 
val result = f() // block until f is completed and return the value 

對於更復雜的工作流程,請查看Scala(或Akka)演員。您還可以看看允許異步IO操作的Java NIO。