Can Scala actors process multiple messages simultaneously?

后端 未结 4 1072
面向向阳花
面向向阳花 2020-12-02 07:03

The reply to a recent question of mine indicated that an actor processed its messages one at a time. Is this true? I see nothing that explicitly says that (in P

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 08:02

    I think that the answer is that an Actor cannot handle messages aynchronously. If you have an Actor which should be listening to messages where these messages can be handled asynchronously, then it could be written like this:

    val actor_ = actor {
    
      loop {
        react {
          case msg =>
            //create a new actor to execute the work. The framework can then 
            //manage the resources effectively
            actor {
              //do work here
            }
          }
        }
      }
    

提交回复
热议问题