Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka Send Delayed Message to self cannot Find implicit ExecutionContext

Tags:

scala

akka

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.

like image 843
Eduardo Avatar asked Jun 25 '13 21:06

Eduardo


2 Answers

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).

like image 192
cmbaxter Avatar answered Nov 02 '22 18:11

cmbaxter


I think I have found it:

import myActorSystem.dispatcher

context.system.scheduler.scheduleOnce(1 second, self, msg)

Now it compiles.

like image 34
Eduardo Avatar answered Nov 02 '22 18:11

Eduardo