EDIT: After discussing and testing with the OP, we found that sending PoisonPill as a means of terminating the observed actor achieves the desired behavior, since the PPill interrupt is processed synchronously while the interrupt or kill is processed asynchronously.
While we are unsure of the reason, our best bet is that killing the actor raises an exception, and PPilling does not.
Apparently, this has nothing to do with using the gracefulStop template in accordance with my initial suggestion, which I will discuss below.
Thus, the solution to the OP problem was only to stop the watched actor sending the PPill by instead sending a Kill message or running the system.stop command.
The old answer starts here:
Maybe I'm going to suggest something a little unrelated, but I think this can be applied.
If I understand correctly what you want to do, it basically interrupts the actor synchronously, i.e. do what comes back only after the actor officially died and his death was recorded (in your case, an observer).
In general, death notification, as well as most of the others in akka, is asynchronous. However, you can obtain a synchronous death confirmation using the gracefulStop template (akka.pattern.gracefulStop).
For this, the code should look something like this:
val timeout = 5.seconds val killResultFuture = gracefulStop(victimRef, timeout, PoisonPill) Await.result(killResultFuture, timeout)
What this does is send a PoisonPill to the victim (note: you can use a special message) that will respond to the future, which will be completed after the death of the victim. Using Await.result, you are guaranteed to be in sync.
Unfortunately, this can only be used if: a) you are actively killing the victim, and instead you do not want to respond to an external cause of death. b) You can use timeouts and locks in your code. But perhaps you can adapt this template to your situation.