【发布时间】:2019-10-25 11:04:16
【问题描述】:
我遇到了以下 SIP:
http://docs.scala-lang.org/sips/pending/spores.html
在阅读的过程中,我遇到了这个例子:
def receive = {
case Request(data) =>
future {
val result = transform(data)
sender ! Response(result)
}
}
那篇文章下面有一段描述:
> Capturing sender in the above example is problematic, since it does not return a stable value. It is possible that the future’s body
> is executed at a time when the actor has started processing the next
> Request message which could be originating from a different actor. As
> a result, the Response message of the future might be sent to the
> wrong receiver.
我不完全理解这一行“在上面的示例中捕获发送者是有问题的......”这不是在每个对 Actor 的请求(请求(数据))中都会创建一个 Future 块的情况?
Future 块的创建是同步的,这意味着当时已知发送者引用。只是该 Future 块的执行以某种方式安排在稍后的时间点发生。
我的理解正确吗?
【问题讨论】:
-
sender是一个方法,而不是一个验证。