Hi Paul, since the failure happens outside of the actor you first have to bring it into the actor so that it can affect the actor—and a message is the only way to do that. “Unsavory” is by definition relative to your taste ;-) but I can say that what you describe is certainly idiomatic actor code (apart from the println—ewwww ;-) ).
Regards, Roland > 4 feb 2016 kl. 23:04 skrev Paul Cleary <[email protected]>: > > I am trying to figure out the best way to handle a failure of a future in an > Actor. > > My use case is interacting with a database, which as you can expect is asynch > / Future based. > > Ideally, I want the actor to restart. > > Here is a relevant code snippet: > > def running: Receive = { > case "do something" => > println("\r\n!!!LOADS STUFF DOING SOMETHING!!!") > Future { > Thread.sleep(100); throw new RuntimeException("I CANT DO ANYTHING :(") > } pipeTo self > > The problem is that the result here is that an `akka.status.Failure` is sent > to the same actor, so I am forced to add something like this in the receive > block: > > case Failure(e) => > println("\r\n\r\neeeeeeeeeeeeeeeeeeee") > throw e > > > This looks unsavory. I have to wrap the exception in an akka.status.Failure > and sent it as a normal message to myself. > > It feels like I should be able to say "if this future fails, then force a > restart on this actor" > > Is there an idiomatic way in Akka to achieve what I am looking for? > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/> > >>>>>>>>>> Check the FAQ: > >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html> > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > >>>>>>>>>> <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] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/akka-user > <https://groups.google.com/group/akka-user>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. Dr. Roland Kuhn Akka Tech Lead Typesafe <http://typesafe.com/> – Reactive apps on the JVM. twitter: @rolandkuhn <http://twitter.com/#!/rolandkuhn> -- >>>>>>>>>> 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 https://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
