这是我的代码:
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
答案 0 :(得分: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]