您应该forward
将消息发送给从属设备(保持相同的发件人),或者将发件人包含在发给从属设备的消息中。例如:
def receive = {
case Calculate => slave ! CalculateWithSender(sender)
case res @ Result(value, originalSender) =>
val result = resultMap(originalSender) + res // assuming results are just added
resultMap += (originalSender -> result)
if (resultsAreFinished(originalSender))
originalSender ! result
}
或者
def receive = {
case Calculate => slave.forward(Calculate)
case res @ Result(value, originalSender) =>
val result = resultMap(originalSender) + res // assuming results are just added
resultMap += (originalSender -> result)
if (resultsAreFinished(originalSender))
originalSender ! result
}
或者
def receive = {
case Calculate => slave.tell(Calculate, sender)
case res @ Result(value, originalSender) =>
val result = resultMap(originalSender) + res // assuming results are just added
resultMap += (originalSender -> result)
if (resultsAreFinished(originalSender))
originalSender ! result
}
我不熟悉 Play 承诺,但?
( ask
) 返回 Akka Future
。如果.asPromise
将 Akka 转换Future
为 Play Promise
,那么您就设置好了。