Akka scheduleOnce回调从未调用过

时间:2018-01-09 14:59:41

标签: scala callback akka scheduler

我有一个简单的问题/错误,但我无法弄清楚什么是幸福的。我想使用ActorSystem scheuler来安排回调。示例代码如下:

implicit val system: ActorSystem = ActorSystem("system-test1")

system.scheduler.scheduleOnce(2 seconds)(() =>
                                         {
                                           println("Hi")
                                         })

但是,没有任何内容打印到控制台,虽然我在println行中有调试器断点,但调试器并没有停在那里。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

system.scheduler.scheduleOnce(2 seconds)(() => { println("Hi") })

上面向scheduleOnce方法传递一个函数,该函数接受零参数并返回Unit。您调用的scheduleOnce方法的版本不会将函数作为参数;它需要一个名为call {name}的参数Unit

final def scheduleOnce(delay: FiniteDuration)(f: => Unit)(implicit executor: ExecutionContext): Cancellable  

因此,只需传入println("Hi"),即Unit

system.scheduler.scheduleOnce(2 seconds)(println("Hi"))
相关问题