Eduardo
Eduardo

Reputation: 8392

Akka Send Delayed Message to self cannot Find implicit ExecutionContext

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.

Upvotes: 11

Views: 6436

Answers (2)

cmbaxter
cmbaxter

Reputation: 35443

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

Upvotes: 16

Eduardo
Eduardo

Reputation: 8392

I think I have found it:

import myActorSystem.dispatcher

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

Now it compiles.

Upvotes: 4

Related Questions