如何在 Akka FSM 中的转换期间访问状态

发布于 2024-12-18 11:04:54 字数 345 浏览 3 评论 0原文

我正在使用 Akka FSM 来处理 Actor 中的状态。我希望每次转换到某个状态时都执行一些操作,无论转换是从哪个状态进行的。阅读文档后,我确信可以这样解决:

onTransition({
  case (_, ToState) => performAction(stateData)
})

...

when(FromState){
  case "changestate" => goto(ToState) using NewStateData
}

但是,当发生转换时,stateData 尚未更新为 NewStateData。

进入某种状态时执行操作的推荐方法是什么?

I am using Akka FSM for handling state in my Actor. I want some actions to be performed every time a transition to a certain state occurs, no matter which state the transition was made from. After reading the docs, I felt certain that this could be resolved like this:

onTransition({
  case (_, ToState) => performAction(stateData)
})

...

when(FromState){
  case "changestate" => goto(ToState) using NewStateData
}

However, when the transition occurs, stateData is not yet updated to NewStateData.

What is the recommended way to perform actions on entering a certain state?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

于我来说 2024-12-25 11:04:54

感谢您提请我注意这一点,这确实是一个疏忽,我立即修复了它(请参阅 票证)。不幸的是,在 1.3 版本发布(应该是下周)之前你无能为力(除了自己合并小补丁之外);如果您特别不耐烦,我将不胜感激,如果您可以尝试 RC2 以及本周将发布的修复程序。

Thanks for bringing this to my attention, that was indeed an oversight, which I fixed immediately (see the ticket). Unfortunately there is not much you can do (apart from merging in the tiny patch yourself) until 1.3 is out, which should be next week; if you are particularly impatient, I would appreciate if you could try out RC2 with the fix which will be released this week.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文