1
可能重複:
What is the Scala equivalent of F#'s async workflows?異步編碼斯卡拉
是否有一個相當於斯卡拉F#異步工作流程?我想用它來同時抓取網頁。
謝謝
可能重複:
What is the Scala equivalent of F#'s async workflows?異步編碼斯卡拉
是否有一個相當於斯卡拉F#異步工作流程?我想用它來同時抓取網頁。
謝謝
並行異步執行一個任務,只要使用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。