Scala actors: receive vs react

前端 未结 5 1059
醉话见心
醉话见心 2020-12-12 11:14

Let me first say that I have quite a lot of Java experience, but have only recently become interested in functional languages. Recently I\'ve started looking at Scala, which

5条回答
  •  借酒劲吻你
    2020-12-12 11:44

    The answer is "yes" - if your actors are not blocking on anything in your code and you are using react, then you can run your "concurrent" program within a single thread (try setting the system property actors.maxPoolSize to find out).

    One of the more obvious reasons why it is necessary to discard the call stack is that otherwise the loop method would end in a StackOverflowError. As it is, the framework rather cleverly ends a react by throwing a SuspendActorException, which is caught by the looping code which then runs the react again via the andThen method.

    Have a look at the mkBody method in Actor and then the seq method to see how the loop reschedules itself - terribly clever stuff!

提交回复
热议问题