gpt4 book ai didi

scala - Scala AKKA Actor 的错误消息

转载 作者:行者123 更新时间:2023-12-04 10:27:32 25 4
gpt4 key购买 nike

这是我的代码:

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

最佳答案

添加类似 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]

关于scala - Scala AKKA Actor 的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11478960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com