我试图实现一个基于Scala的actor API的计时器,当前的Thread actor(Actor.self)作为计时器和一个匿名的Actor,它完成需要及时完成的工作.我有以下Scala程序
import scala.actors.Actor.self
import scala.actors.TIMEOUT
object Main {
def main(args: Array[String]): Unit = {
val thiz = self
actor {
// do heavy work here
thiz ! "finish"
}
self.reactWithin(1000) {
case "finish" => println("complete")
case TIMEOUT => println("timeout")
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,我收到了
Exception in thread "main" scala.actors.SuspendActorControl
scala.actors.ActorProxy@1d99a4d: caught java.lang.InterruptedException
Run Code Online (Sandbox Code Playgroud)
请告诉我解决问题的方法.