Scala中的异步编码
可能重复:Scala中的异步编码,scala,web-crawler,Scala,Web Crawler,可能重复: Scala中是否有与F#异步工作流等效的工作流?我想用这个同时抓取网页 谢谢要并行异步执行任务,只需使用Actor.Actor方法: import scala.actors.Actor._ actor { // code here is excuted asynchronously } 要执行任务并等待结果,请使用futures: import scala.actors.Futures.future val f = future { // code here is
Scala中是否有与F#异步工作流等效的工作流?我想用这个同时抓取网页
谢谢要并行异步执行任务,只需使用
Actor.Actor
方法:
import scala.actors.Actor._
actor {
// code here is excuted asynchronously
}
要执行任务并等待结果,请使用futures:
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)参与者。您还可以看看JavaNIO,它允许异步IO操作