我不明白,为什么我得到了一个重载错误内“timers.startTimerWithFixedDelay”。我添加了3个参数,以确保采取正确的方法,但似乎他也发现只有2个参数的方法非常有吸引力。
package main
import akka.actor.typed.{ActorSystem, Behavior}
import akka.actor.typed.receptionist.Receptionist
import akka.actor.typed.scaladsl.Behaviors
import scala.concurrent.duration.{Duration, FiniteDuration, MINUTES}
object Guardian {
case object Tick
val start: Behavior[Nothing] =
Behaviors.setup[Receptionist.Listing] { context =>
Behaviors.withTimers { timers =>
timers.startTimerWithFixedDelay(Tick, Tick, FiniteDuration(Duration("3 seconds").toSeconds, MINUTES))
Behaviors.same
}
}.narrow
}
object Application extends App {
ActorSystem[Nothing](Guardian.start, "system")
}
在TimerScheduler.scala内部,它看起来像,他不能在以下两者之间做出决定:
def startTimerWithFixedDelay(msg: T, delay: FiniteDuration): Unit
def startTimerWithFixedDelay(key: Any, msg: T, delay: FiniteDuration): Unit
他为什么不选参数为3的那个?
编译器错误消息:
[error] ... overloaded method startTimerWithFixedDelay with alternatives:
[error] (msg: akka.actor.typed.receptionist.Receptionist.Listing,delay: scala.concurrent.duration.FiniteDuration)Unit <and>
[error] (key: Any,msg: akka.actor.typed.receptionist.Receptionist.Listing,delay: scala.concurrent.duration.FiniteDuration)Unit
1条答案
按热度按时间s5a0g9ez1#
Tick
不是Receptionist.Listing
,因此两个版本都不匹配。