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 
      }
   })
  }
 }
}

!     异步发送,没有返回值

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

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

原文地址:https://www.cnblogs.com/144823836yj/p/10727555.html