Now I wanna an actor to send messages to other actors and at the same time receive messages from others. It seems I need use multi threads in Akka. Below is my code:
def receive = {
case Rumor => {
count+=1;
if ...
else self ! Sleep(FiniteDuration(20, "millis"))
}
case Sleep(duration) => {
case object WakeUp
context.system.scheduler.scheduleOnce(duration, self, WakeUp)
context.become(
{
case WakeUp => context.unbecome()
others ! Rumor
}, discardOld = false
)
}
case _=> .....
}
my problem are:
1) I am not sure my code would work as I expect. Reference use Akka scheduler inside an actor
2) I already import
import scala.math._
import akka.actor._
import scala.util.Random
import scala.concurrent.duration._
but the compiler still reports error on:
error: Cannot find an implicit ExecutionContext, either require one yourself or import ExecutionContext.Implicits.global
context.system.scheduler.scheduleOnce(duration, self, WakeUp)