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

Scala演员:如果反应没有返回,为什么需要循环{},为什么不(true)

发布时间:2020-12-16 09:17:43 所属栏目:安全 来源:网络整理
导读:刚刚开始 Scala演员. Scala website说: Thread-blocking operations can be avoided by using react to wait for new messages (the event-based pendant of receive ). However,there is a (usually small) price to pay: react never returns. … Note th
刚刚开始 Scala演员. Scala website说:

Thread-blocking operations can be avoided by using react to wait for
new messages (the event-based pendant of receive). However,there is a
(usually small) price to pay: react never returns.

Note that using react inside a while loop does not work! However,
since loops are common there is special library support for it in form
of a loop function. It can be used like this:

loop {
  react {
    case A => ...
    case B => ...
  }
}

我现在很困惑 – 似乎有一个矛盾:

a)如果反应没有返回,那么把它放在一个循环中是什么意思?

b)由于循环重复执行一个块,它与…(true)有什么不同 – 为什么不工作,以什么方式“不工作”?

解决方法

这两个功能,循环和反应都不是纯粹的.循环通过name参数进行调用,并对原始actor的两个set变量做出反应.这是因为一个演员一直没有附加线程.只有当消息框中有消息时,它才会变为活动状态.这就是为什么一段时间(true)会导致100%的CPU使用率,而演员没有响应.

(编辑:李大同)

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

    推荐文章
      热点阅读