Hi,
Is there any registerOnTermination function alternative in Akka typed actors just like classic actors?
Can’t seem to find any function?
Regards,
Syed
Hi,
Is there any registerOnTermination function alternative in Akka typed actors just like classic actors?
Can’t seem to find any function?
Regards,
Syed
That’d be whenTerminated for Scala and getWhenTerminated for Java.
@johanandren thanks for reply, this is what I was looking for
@johanandren It seems the behavior of whenTerminated and registerOnTermination aren’t same, with registerOnTermination you could run some code on termination. With whenTerminated I tried OnComplete and map to run my code but my code doesn’t run.
Regards,
Syed
Since the whenTerminated completes when the system has shut down it will not be possible to run it on the system dispatcher (which will have shut down, since the actor system did). You will have to run such callbacks on for example the global Scala execution context rather.
If the task really needs to use actor system facilities and run things inside the actor system to shut down, you can hook into one of the coordinated shutdown phases, see docs: https://doc.akka.io/docs/akka/current/coordinated-shutdown.html#coordinated-shutdown
Why not using PostStop signal ?