演员相对于未来的优势
我目前从事Futures编程,对演员很好奇。我想听听有经验的声音:
- 演员相对于未来有什么优势?
- 我什么时候应该使用其中一种而不是另一种?
据我所知,演员持有状态而期货则不持有,这是唯一的区别吗?所以如果我有真正的不变性我就不应该关心演员?
请赐教:-)
I currently program in Futures, and I'm rather curious about actors. I'd like to hear from an experienced voice:
- What are the advantages of actors over futures?
- When should I use one instead of other?
As far as I've read, actors hold state and futures doesn't, is this the only difference? So if I have true immutability I shouldn't care about actors?
Please enlighten me :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个重要的区别是,Actor 通常具有内部状态,因此从理论上讲,它们是不可组合的;请参阅此和这篇博客文章解决了一些问题详细阐述。然而,在实践中,它们通常在命令式方法和纯功能性方法之间提供了一个最佳点。因此,如果可能的话,建议坚持仅使用 future 进行编程,但如果消息传递模型更适合您的问题领域,请随意使用 actor。
One important difference is that actors typically have internal state, and therefore theoretically, they are not composable; see this and this blog post for having some issues elaborated. However, in practice, they usually provide a sweet spot between the imperative and the purely functional approach. So if possible, it is recommended to stick to programming with only futures, but if the message-passing model fits your problem domain better, feel free to use actors.