I am using Akka 2.1.4. I need one of my actors to send a delayed message to itself.
I have tried, from within the Actor's receive
:
context.system.scheduler.scheduleOnce(1 second, self, msg)
However, it does not compile, since it cannot find the implicit ExecutionContext. Where can I get it from?.
NOTE: I am aware that the actual sender will not be my actor, but that is OK, since I don't need to know who the sender is.
You could also do it like this:
class MyActor extends Actor{
import context._
...
}
This way you are assured that you are getting the dispatcher assigned to that actor in case it differs from the main dispatcher for the system (which is what you are getting with your solution).
I think I have found it:
import myActorSystem.dispatcher
context.system.scheduler.scheduleOnce(1 second, self, msg)
Now it compiles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With