简体   繁体   English

找不到参数超时的隐式值:akka.util.Timeout

[英]could not find implicit value for parameter timeout: akka.util.Timeout

I have this code, where I am making an ask request in Scala: 我有以下代码,在Scala中提出询问请求:

someActorRef ? SomeMessage()

However, I'm getting this message: 但是,我收到此消息:

could not find implicit value for parameter timeout: akka.util.Timeout

I also tried this: 我也试过这个:

Await.ready(someActorRef ? SomeMessage(), Duration("3 seconds")).asInstanceOf[String]

But I get the same message. 但是我得到了同样的信息。

Anyway, I don't want to block. 无论如何,我不想阻止。 I want to get a Future and then later on give it an onComplete callback. 我想要一个Future ,然后再给它一个onComplete回调。

Can I ask for a message from another actor without blocking? 我可以要求其他演员发信息而不加阻挡吗?

ask needs an implicit Timeout , after which it will just fail the Future with a TimeoutException . ask需要一个隐式的Timeout ,之后它只会通过TimeoutException使Future失败。

import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.duration._

implicit val timeout = Timeout(5 seconds)
val f = someActorRef ? SomeMessage()

Note that nothing will block for those 5 seconds, the ask pattern is fully async/non-blocking. 请注意,在这5秒钟内没有任何内容会阻塞, ask模式是完全异步/非阻塞。 It will give you back a Future , on which you can block (NOT RECOMMENDED) or attach a callback (as you wish) 它将带给您Future ,您可以在其上阻止(不推荐)或附加回调(如您所愿)

f.onComplete(doSomething(_))

More info here . 更多信息在这里

You can. 您可以。 But don't use ask . 但是不要用ask Just pipe result to the sender. 只是pipe导致给发件人。 Eg let's say this is an actor which performs long running task and returns a future: 例如,假设这是一个执行长期任务并返回未来的演员:

class LongRunningTaskPerformer extends Actor {
  import context.dispatcher

  override def receive: Receive = {
    case PerformTask => someLongRunningTask() pipeTo sender()
  }
}

class QueryPerformer extends Actor {

  val longRunningTaskPerformer = context.actorOf(LongRunningTaskPerformer.props())  

  override def receive: Receive = {
    case TriggerLongRunningTask => longRunningTaskPerformer ! PerformTask
    case result @ Result         => // do something with your result
  }
}

In this case, I'm sending a message PerformTask to LongRunningTaskPerformer actor. 在这种情况下,我正在向LongRunningTaskPerformer actor发送一条消息PerformTask When the future is being completed, result will be sent to my QueryPerformer . 当将来完成时,结果将发送到我的QueryPerformer No blocking. 无阻塞。 Easy. 简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Akka播放2.5 - 找不到参数超时的隐含值:akka.util.Timeout - Play 2.5 with Akka - could not find implicit value for parameter timeout: akka.util.Timeout Play Framework 2.2 - 找不到参数超时的隐含值 - Play Framework 2.2 - could not find implicit value for parameter timeout 找不到参数FromRequestUnmarshaller Akka的隐式值 - could not find implicit value for parameter FromRequestUnmarshaller Akka akka-http:找不到参数解组的隐含值 - akka-http : could not find implicit value for parameter unmarshalling 找不到参数系统的隐含值:akka.actor.ActorSystem - could not find implicit value for parameter system: akka.actor.ActorSystem 这作为隐式参数-找不到参数的隐式值 - this as implicit parameter - could not find implicit value for parameter 无法找到参数的隐含值 - Could not find implicit value for parameter IO(Http)导致错误“无法找到参数系统的隐式值:akka.actor.ActorSystem” - IO(Http) is cause the error “could not find implicit value for parameter system: akka.actor.ActorSystem” 错误:找不到参数p的隐式值:scala.slick.jdbc.SetParameter [java.util.UUID] - Error:could not find implicit value for parameter p: scala.slick.jdbc.SetParameter[java.util.UUID] Slick:找不到参数 e 的隐式值:slick.jdbc.SetParameter[Option[java.util.UUID]] - Slick: could not find implicit value for parameter e: slick.jdbc.SetParameter[Option[java.util.UUID]]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM