7

这是我的代码:

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

我收到这条线的错误:

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

错误是:

找不到参数超时的隐式值:akka.util.Timeout

4

1 回答 1

13

添加类似的东西implicit val timeout = Timeout(5 seconds)。见http://doc.akka.io/docs/akka/2.0.1/scala/futures.html

顺便说一句,你还需要改变

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

test = Await.result(myActor ? "test", timeout.duration).asInstanceOf[String]
于 2012-07-13T22:20:31.103 回答