gpt4 book ai didi

playframework - 在游戏中使用 Actor

转载 作者:行者123 更新时间:2023-12-04 06:21:07 25 4
gpt4 key购买 nike

我跟着剧本描述如何使用 Actor :https://www.playframework.com/documentation/2.4.x/ScalaAkka他们建议如下:

@Singleton
class Application @Inject() (system: ActorSystem) extends Controller {

val helloActor = system.actorOf(HelloActor.props, "hello-actor")

//...
}

但这导致:
play.sbt.PlayExceptions$CompilationException: Compilation error[trait Singleton is abstract; cannot be instantiated]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.11.6.jar:na]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.11.6.jar:na]
at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na]
at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17) ~[na:na]

Tos 看看我做了什么或跟着做: https://github.com/dataplayground/playground

编辑:

删除 @Singleton造成:
could not find implicit value for parameter timeout: akka.util.Timeout

这是代码:
implicit val timeout = 5.seconds

def sayHello(name: String) = Action.async {
(helloActor ? SayHello(name)).mapTo[String].map { message =>
Ok(message)
}
}

最佳答案


implicit val timeout = akka.util.Timeout(5.seconds)

import javax.inject.Singleton

关于playframework - 在游戏中使用 Actor ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33916684/

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