加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

简单的Scala演员问题

发布时间:2020-12-16 09:03:58 所属栏目:安全 来源:网络整理
导读:我确信这是一个非常简单的问题,但不好意思说我无法理解它: 我在Scala中有一个值列表. 我想使用use actors与每个值并行地进行一些(外部)调用. 我想等到所有值都被处理完毕,然后继续. 没有修改共享值. 有人可以建议吗? 谢谢 解决方法 Scala中有一个演员使用
我确信这是一个非常简单的问题,但不好意思说我无法理解它:

我在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())

你去吧只是.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读