Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error message with Scala AKKA Actor

Tags:

scala

akka

Here is my code:

class testActor extends Actor   {
    var test = "test2"
    def receive = {
            case "test" ⇒
                    "works"
    }
} 

def test = Action {
    var test = "test"
    val system = ActorSystem("MySystem")
    val myActor = system.actorOf(Props[testActor.testActor], name = "testActor")

    test = Await.result(myActor ? "test", Duration(1, TimeUnit.SECONDS))
}

I am getting an error with this line:

test = Await.result(myActor ? "test", Duration(1, TimeUnit.SECONDS))

The error is:

could not find implicit value for parameter timeout: akka.util.Timeout

like image 226
user1491739 Avatar asked Jul 13 '12 22:07

user1491739


1 Answers

add something like implicit val timeout = Timeout(5 seconds). See http://doc.akka.io/docs/akka/2.0.1/scala/futures.html

By the way, you'll also need to change

def receive = {
        case "test" ⇒ sender ! "works"
}

and

test = Await.result(myActor ? "test", timeout.duration).asInstanceOf[String]
like image 136
brandon Avatar answered Nov 05 '22 14:11

brandon