I have the following code:
import scala.concurrent.Future
import scala.concurrent.Promise
import scala.concurrent.duration.DurationInt
import scala.concurrent.duration.FiniteDuration
import akka.actor.Actor
import akka.actor.ActorRef
import akka.pattern.ask
import akka.util.Timeout.durationToTimeout
trait ActorHelpers {
self: Actor =>
import context.dispatcher
def keepAsking(recipient: ActorRef, msg: Any, interval: FiniteDuration):
Future[Any] = {
val p = Promise[Any]()
val cancel = context.system.scheduler.schedule(0.millis, interval) {
if (context != null)
(recipient ? msg)(1.hour) foreach p.trySuccess
}
val f = p.future
f.onComplete(_ => cancel.cancel())
f
}
}
The idea of this code snippet is that a message is resend as long as an
answer is retrieved. The problem is that I sometimes get a NPE on the line
that contains the ask.
Without the check if context is null I get even more NPEs. I don't
understand why I get NPEs here, because I can't see where context or some
of its state is accessed. Can someone explain it?
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> 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/groups/opt_out.