假设我从一些URL下载了一个(可能很大的)图像列表.我正在使用Scala,所以我要做的是:
import scala.actors.Futures._
// Retrieve URLs from somewhere
val urls: List[String] = ...
// Download image (blocking operation)
val fimages: List[Future[...]] = urls.map (url => future { download url })
// Do something (display) when complete
fimages.foreach (_.foreach (display _))
Run Code Online (Sandbox Code Playgroud)
我对Scala有点新意,所以对我来说这看起来仍然有些神奇:
display _)是否会在主线程上执行,如果没有,我该如何确定呢?谢谢你的建议!