FSM vs become/unbecome in Akka

前端 未结 2 509
后悔当初
后悔当初 2021-02-01 19:59

Akka provides two somewhat overlapping ways to manage actor states, Finite State Machines and unbecome/become. What are their respective benefits/drawbacks? When should one of t

2条回答
  •  既然无缘
    2021-02-01 20:19

    Become/Unbecome are very lightweight in contrast to FSMs. So unless you have more than 2 states (on/off for example) and/or complex state change policies I wouldn't convert Become/Unbecome to a full blown FSM. Other then that, I think there are only minor differences...Like for example FSMs give you a nice built in timer DSL:

    setTimer("TimerName", msg, 5 seconds, repeat = true)
    // ...
    cancelTimer("TimerName")
    

    Or for instance I'm not sure if it's possible in an FSM to "go back" to the previous state, there is only "go forward", since you have to explicitly specify which state to go to. Whereas unbecome gives you exactly that.

提交回复
热议问题