One way to do it would be to have a supervisor actor be responsible for
opening and closing the actor, and instantiating MyActor.  Then, the
supervisor actor can deathwatch for the actor and close the writer, or
close the writer through the supervisorStrategy on exception.

Will Sargent
Consultant, Professional Services
Typesafe <http://typesafe.com>, the company behind Play Framework
<http://www.playframework.com>, Akka <http://akka.io> and Scala
<http://www.scala-lang.org/>

On Sun, Nov 16, 2014 at 2:46 PM, Jelmer Kuperus <jkupe...@gmail.com> wrote:

> Hi I am new to using akka and I am running into the following issue
>
> I have an actor written in a funcrtional style that roughly looks like
> this :
>
> class MyActor extends Actor  {
>
>   def awaitCompletion(writer: writer) = {
>     case Add(message) => {
>       writer.write(message)
>       context.become(awaitCompletion(writer))
>     }
>     case Done => {
>       writer.close()
>       context.become(awaitStart())
>   }
>
>   def awaitStart(): Receive = {
>     case Start => {
>        ....
>       context.become(awaitCompletion(someWriter))
>     }
>   }
>
>   def receive: Receive = awaitStart()
>
> }
>
> It uses a writer that needs to be closed when the Done message is
> received. Which will work fine under normal conditions, but I also want to
> make sure the resource gets closed if the actor dies of abormal causes
> Since the state of the actor is part of the function and not an instance
> variable  I cannot do anything from my postStop. So how would I close this
> resource in that case ?
>
>
>
>  --
> >>>>>>>>>> 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 akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to