Actor消息发送及等待结果关键字

时间:2023-03-09 04:15:06
Actor消息发送及等待结果关键字
class Task extends Actor{
override def act(): Unit = {
while(true){
receive({
case SmTask(file) =>{
val lines: List[String] = Source.fromFile(file).getLines().toList
val words: List[String] = lines.flatMap(_.split(" "))
val res: Map[String, Int] = words.map(_, 1).groupBy(_._1).mapValues(_.size) // 异步发送结果,没有返回值
sender ! res
}
})
}
}
}

!     异步发送,没有返回值

!?   同步发送消息,等待返回值

!!   异步发送消息,等待返回值