Reputation: 9273
I'm trying to collect a List of Future custom object from Akka actors, this is my code:
var game_manager_backends: List[ActorRef] = List()
implicit val ec = context.dispatcher
val taskFutures: List[Future[Game]] = game_manager_backends map { gm_be =>
implicit val timeout = Timeout(5 seconds)
val result = gm_be ? GameStatus
}
val searchFuture = Future sequence taskFutures
searchFuture.onSuccess {
case results: List[Game] => origin ! results
}
This
game_manager_backends
is the List that contains all actor i want to ask a Game
object, then i want collect all this Game
Objects in a List and send back to the origin actor, with this implementation this is the error that give me on the map
line:
type mismatch; found : List[Unit] required: List[scala.concurrent.Future[common.Game]]
How can I solve this problem?
Thanks
Upvotes: 1
Views: 231
Reputation: 2095
Change val result = gm_be ? GameStatus
to val result = (gm_be ? GameStatus).mapTo[Game]
. You also don't need it to be a val
.
Upvotes: 0
Reputation: 6385
You get Unit
cause do not return any value inside map
(fix for this proposed above in comment).
?
ask on akka returns Future[Any]
but you want Future[common.Game]
to fix this - extra mapping required.
result map {
case a@Game => a
}
Upvotes: 0