0
[error] DeviceAffiliationCluster.scala:56: value ask is not a member of akka.actor.ActorRef
[error]   def ask(msg: Any): Future[Any] = deviceRegion.ask(msg)
[error]                                                 ^
[warn] DeviceAffiliationCluster.scala:5: Unused import
[warn] import akka.pattern.ask

akka.pattern.ask supplies an implicit conversion (from ActorRef to AskableActorRef, the latter which provides the method ask)

When I compile using sbt, however, the conversion is NOT recognized. (Intellij sees the implicit conversion and has no issue with it, but I'm using sbt to build.)

I can get it to work explicitly:

val deviceRegion: ActorRef =  ...

val deviceRegionAskable: AskableActorRef = deviceRegion
Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
tpdi
  • 34,554
  • 11
  • 80
  • 120

1 Answers1

2

the problem is that your method ask is hiding the ask method which you imported from akka.pattern.ask If you use a different method name then your example works fine

  import akka.actor._
  import akka.pattern.ask
  import scala.concurrent.duration._
  import scala.concurrent._

  class FooActor extends Actor {
    def receive = {
    case s: String => sender ! s"Hello $s"
    }}
  val ac = ActorSystem()
  implicit val ec : ExecutionContext = ac.dispatcher
  val fooAc = ac.actorOf(Props[FooActor], "fa")
  implicit val to = new akka.util.Timeout(10 seconds)
  def ask2(msg: Any) : Future[Any] = fooAc.ask("foo")
  val x = Await.result(ask2("foo"), Duration.Inf)
  println(x)
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
  • Oh, sheesh! Thank you. – tpdi Feb 26 '18 at 21:40
  • But, wait, I was looking for an ask on deviceRegion, a member val, not on this. – tpdi Feb 26 '18 at 21:56
  • ask is an implicit method which will not be provided to you, if there was already an ask in the context. if there is no ask then the implicit mechanism looks for the ask and finds it in the import of akka.patten.ask. – Knows Not Much Feb 26 '18 at 22:00