【问题标题】:Akka Send Delayed Message to self cannot Find implicit ExecutionContextAkka Send Delayed Message to self 找不到隐式 ExecutionContext
【发布时间】:2013-06-22 20:47:10
【问题描述】:

我正在使用 Akka 2.1.4。我需要我的一个演员向自己发送延迟消息。

我已经尝试过,来自 Actor 的receive

context.system.scheduler.scheduleOnce(1 second, self, msg)

但是,它无法编译,因为它找不到隐式的 ExecutionContext。我可以从哪里得到它?。

注意:我知道实际的发件人不会是我的演员,但这没关系,因为我不需要知道发件人是谁。

【问题讨论】:

    标签: scala akka


    【解决方案1】:

    你也可以这样做:

    class MyActor extends Actor{
      import context._
      ...
    }
    

    这样你就可以确保你得到分配给那个actor的调度器,以防它与系统的主要调度器不同(这是你的解决方案所得到的)。

    【讨论】:

      【解决方案2】:

      我想我找到了:

      import myActorSystem.dispatcher
      
      context.system.scheduler.scheduleOnce(1 second, self, msg)
      

      现在它可以编译了。

      【讨论】:

        猜你喜欢
        • 2022-12-02
        • 2013-02-04
        • 1970-01-01
        • 2016-04-28
        • 2022-12-19
        • 2016-01-23
        • 1970-01-01
        • 2015-12-02
        • 1970-01-01
        相关资源
        最近更新 更多