代码之家  ›  专栏  ›  技术社区  ›  yalkris

演员中的scala list.par

  •  0
  • yalkris  · 技术社区  · 6 年前

    我尝试使用list.par来实现并行性,以便在演员内部执行某些操作。像下面这样

    MyActor {
         myList.par.map {
              listItem => doSomething(listItem)
         }
    }
    

    1 回复  |  直到 6 年前
        1
  •  0
  •   Ramón J Romero y Vigil    6 年前

    the documenation

    每个参与者都被配置为在MessageDispatcher上运行 dispatcher兼作ExecutionContext。如果未来的本质 参与者调用的调用与 需求),那么就可以最容易地重用dispatcher 通过导入context.dispatcher运行未来。

    class A extends Actor {
      import context.dispatcher
      val f = Future("hello")
      def receive = {
        case _ ⇒
      }
    }