I'm using secure social and akka to send messages to a web client via a web socket using play frame work 2.3 Websocket
def feedWS = WebSocket.tryAccept[JsValue] { implicit request =>
SecureSocial.currentUser[PDUser].map {
maybeUser => maybeUser match {
case Some(user) =>
Right(Feed.start(user.id))
case None => {
Left(Redirect("/login"))
}
}
}
But the map returns a future and Feed.start returns an future too. Something like Object serving ws and connecting to an actor that pumps messages out (actor works fine)
def start(user: String): Future[(Iteratee[JsValue, _], Enumerator[JsValue])] = {
(actorFor(user) ? connect(user)).map {
case ConnectedE(enumerator) => {
val iteratee = Iteratee.foreach[JsValue] { event =>
val things = FromJson.aList(event)
actorFor(user) ! Subscribe(things)
}.map { _ =>
log.info("Disconnected")
actorFor(user) ! UnSubscribe
}
(iteratee, enumerator)
}
}
}
How do I compose them, if indeed I can or does it need an await? At the moment I have a future of a future.