Consider the below code:
class TestActor extends Actor {
def receive = {
case "hello" =>
sender ! Future {
"Sample future result"
}
}
}
I have the below route defined:
def r5: Route = {
pathPrefix("check") {
onSuccess(system.actorOf(Props[TestActor]).ask("hello")) {
successResult =>
complete {
"The result is " + successResult
}
}
}
}
When I access the route, I get the output as The result is Success(Sample future result)
while I expected it to be The result is Sample future result
. From the docs here about onSuccess:
Evaluates its parameter of type Future[T], and once the Future has been completed successfully, extracts its result as a value of type T and passes it to the inner route.
and the example given is:
val route =
path("success") {
onSuccess(Future { "Ok" }) { extraction =>
complete(extraction)
}
}
So where am I going wrong?