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

 

!     异步发送,没有返回值

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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

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

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄