【发布时间】:2015-03-28 11:23:28
【问题描述】:
比如说,我有一个 Actor,它的接收函数喜欢
def receive = {
case Message =>
val doFuture: Future[String] = doSomething()
doFuture onSuccess {
case doResult =>
//////////// Here is the problem !! /////////////
// --> here fail. Seems sender cannot send back the result to the caller
sender ! doResult
}
doFuture onFailure {
// handle exception
}
}
为什么发件人不能再发回消息了?
【问题讨论】:
-
您正在关闭发件人(它是可变的)。到未来完成时,发件人不一定有效/不再相同。见stackoverflow.com/questions/16898131/sender-inside-a-future
-
通过添加
import context.dispatcher确保未来在Actors执行上下文中执行 -
谢谢!抱歉重复的问题..