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 } }) } } }
! 异步发送,没有返回值
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。!? 同步发送消息,等待返回值
!! 异步发送消息,等待返回值

更多精彩