That might work.
Just know that even if the actor was alive when you checked, when the next
line of your code is executing it might be dead. I use the following
pattern:
Parent create child actors, and puts them in a map.
Child must request shutdown from parent
Parent receives this request, and removes the actor from the map and sends
it a "shutdown"-message
The child receives it, does some final cleanup, and stops itself.
This works for me because the parent delegates messages to the child, and
this way the child is never stopped AND is in the map at the same time.
Best regards,
Anders
tirsdag 21. april 2015 16.09.55 UTC+2 skrev Andrew Easter følgende:
>
> Thanks for your reply.
>
> In my case, I'm not really interested in knowing exactly when the child
> stops. I simply want to know whether context.child would no longer return
> Some(ActorRef) once the child has stopped. Reason being that I'm
> essentially using context.child to lookup children by name, somewhat akin
> to a Map - using context.child seems to avoid explicitly having to create
> my own Map and waiting on Terminated messages to remove children as they
> stop.
>
>
> On Tuesday, 21 April 2015 12:28:36 UTC+1, Anders Båtstrand wrote:
>>
>> You have to watch the actor to receive the Terminated-message when it
>> stops.
>>
>> context watch childActor
>>
>> As for the question about context.child, I don't know (never used that
>> one myself)....
>>
>> Regards,
>>
>> Anders
>>
>> tirsdag 21. april 2015 09.58.25 UTC+2 skrev Andrew Easter følgende:
>>>
>>> I've struggled to find any explicit documentation to state how a parent
>>> actor reacts to a child actor stopping itself.
>>>
>>> If a child actor calls:
>>>
>>> context stop self
>>>
>>> Will its parent be notified that the child has stopped such that a call
>>> within the parent to:
>>>
>>> context.child("<name_of_stopped_child>")
>>>
>>> will - once the child has completely stopped - eventually return None?
>>>
>>>
>>>
>>>
>>>
>>>
>>>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.