我尝试编写示例代码来结合 akka 和 actor。但是我在编译代码时收到了错误消息。
代码非常简单,如下所示。
那么,我做错了什么?
[error] /home/qos/workspaces/actors/actors.scala:20: type mismatch;
[error] found : Unit
[error] required: scala.sys.process.ProcessLogger
[error] execute(cmd)
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
代码是
import scala.sys.process._
import akka.actor._
object TryActor {
def main(args: Array[String]) {
val akkaSystem = ActorSystem("akkaSystem")
val worker = akkaSystem.actorOf(Props[Worker], name = "work0")
worker ! Command("ls")
}
case class Command(cmd: String)
class Worker extends Actor {
def receive = {
case Command(cmd) => {
println(cmd)
"echo recieve message from someone" !
execute(cmd.toString)
}
}
def execute(cmd: String) {
val process = Process(cmd.toString)
process ! ProcessLogger(_ => {})
}
}
}