Using Futures in Akka Actors

前端 未结 3 1138
无人共我
无人共我 2021-02-02 17:06

I\'m just starting to learn Akka Actors in Scala. My understanding is that messages received by an Actor are queued in an Actor\'s mailbox, and processed one at a time. By pro

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 17:13

    Remember two things

    1. The notion behind the term Future(a special actor) is that we can create an actor for any result while it(the result) is still being computed, started or finished but we can't have an address for that special actor or future.

    2. Suppose I want to buy something (my result is buying something, and the process it to initiate steps to start buying procedure) we can create an actor for the result (buy) but if there is any problem and we can't buy the thing we will have an exception instead of the result.

    Now how the above two things fit is explained below-

    Say we need to compute the factorial of 1 billion we may think that it will take a lot of time to compute but we get the Future immediately it will not take time to produce the Future (" Since the future is async, the Actor could begin processing the next several messages while the future associated with the prior message is still running."). Next, we can pass this future, store it and assign it.

    Hope so you understand what I'm trying to say.

    Src : https://www.brianstorti.com/the-actor-model/

提交回复
热议问题