遇到Akka 2.1.2 Scheduler问题('system'无法识别)

根据这些示例,我试图让一个非常简单的循环函数循环运行:

http://doc.akka.io/docs/akka/2.1.2/scala/scheduler.html

代码:

import akka.actor.Actor
import akka.actor.Props
import scala.concurrent.duration._

object Main extends Application {
  val system = akka.actor.ActorSystem("system")    // this was missing!
  import system.dispatcher

  system.scheduler.schedule( 0 milliseconds, (10*1000) milliseconds, {
    println( "click!" )
  })
}

我得到(sbt):

> .../src/Main.scala:34: not found: value system [error]       import
> system.dispatcher [error]              ^ [error]
> .../src/Main.scala:36: not found: value system [error]      
> system.scheduler.schedule( 0 milliseconds /*initial delay*/,
> (entry.secs*1000) milliseconds /*delay between*/, { [error]       ^

system 应该来自哪里?

Addendum:

我'm having the code within a ' main()' function, and I haven' t继承了 ActorActorSystem 中的任何内容 . 关键是我想安排功能,但没有进入演员 . 框架是否必须从某种东西中衍生出来(如果是这样,那应该说出来了吗?) .

回答(1)

3 years ago

import system.dispatcher 之前,它看起来像是缺少以下表达式:

val system = akka.actor.ActorSystem("system")