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

 

!     异步发送,没有返回值

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

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

 

posted @ 2019-04-18 09:16  梦醒江南·Infinite  阅读(345)  评论(0编辑  收藏  举报