我确信这是一个非常简单的问题,但不好意思说我无法理解它:
我在Scala中有一个值列表.
我想使用use actors与每个值并行地进行一些(外部)调用.
我想等到所有值都被处理完毕,然后继续.
没有修改共享值.
有人可以建议吗?
谢谢
解决方法
Scala中有一个演员使用的类正是为了这类问题而准备的:期货.这个问题会像这样解决:
// This assigns futures that will execute in parallel // In the example,the computation is performed by the "process" function val tasks = list map (value => scala.actors.Futures.future { process(value) }) // The result of a future may be extracted with the apply() method,which // will block if the result is not ready. // Since we do want to block until all results are ready,we can call apply() // directly instead of using a method such as Futures.awaitAll() val results = tasks map (future => future.apply())
你去吧只是.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。