【发布时间】:2017-09-28 00:57:14
【问题描述】:
我正在阅读有关typed actors 的信息,类型化的演员提供的界面如下所示:
trait Squarer {
def squareDontCare(i: Int): Unit //fire-forget
def square(i: Int): Future[Int] //non-blocking send-request-reply
def squareNowPlease(i: Int): Option[Int] //blocking send-request-reply
def squareNow(i: Int): Int //blocking send-request-reply
@throws(classOf[Exception]) //declare it or you will get an UndeclaredThrowableException
def squareTry(i: Int): Int //blocking send-request-reply with possible exception
}
这与简单的 Future 有何不同?
它们看起来确实很相似,def square(i: Int): Future[Int] 的界面相同。
类型化的actors是位置透明的(并且可以在其他节点上运行)但Futures不是吗?
所以类型化的actors可以被认为是一种更受限制的Futures形式?从某种意义上说,Future 构造受到限制,因此对于将来的构造,不能使用任何不能通过电线(不可序列化)的东西。例如,闭包(或任何函数)不能传递给类型化的 Actor,但可以用于构造 Future。
【问题讨论】:
-
Typed Actors:“该模块将被弃用,因为它将被当前以开放预览模式开发的 Akka Typed 项目所取代。” “类型化的 Actor 非常适合在 Actor 系统(“内部”)和非 Actor 代码(“外部”)之间架起桥梁,因为它们允许您在外部编写正常的 OO 外观代码。”
标签: scala akka future typedactor