I'm using ask
(?
) to get a value which is of type Set[String]
from an Actor. However, the actor returns Future[Any]
.
What is the correct way to convert this Future[Any]
to Future[Set[String]]
?
val result : Future[Any] = myactor ? GetSomeValue
//convert Future[Any] to Future[Set[String]]
There is method called mapTo
available on Futures:
val result : Future[Set[String]] = (myactor ? GetSomeValue).mapTo[Set[String]]
It will raise an Exception if the cast is not successful. From the docs:
Creates a new Future[S] which is completed with this Future's result if that conforms to S's erased type or a ClassCastException otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With