joesan
joesan

Reputation: 15435

Akka Actor Returning a Future to the Sender

I have an Actor that responds to the sender by returning a Future[String]. Here is the code bit:

case PingTsdb => {
    sender ! someService.getVersion // returns a Future[String]
  }

The getVersion method returns a Future[String], but when I run this method, I get the following error:

Cannot cast scala.concurrent.impl.Promise$KeptPromise to java.lang.String

I understand that it is trying to cast the Future[String] into a String, but how do I get this actor to work? I can write an onComplete handler on the getVersion method return value, but is there a better approach?

Upvotes: 1

Views: 566

Answers (1)

joesan
joesan

Reputation: 15435

I figured that out. I had to use the pipeTo method from the akka.ask pattern!

getTsVersion pipeTo sender

It was as simple as that!

Upvotes: 2

Related Questions