Skip to content

Instantly share code, notes, and snippets.

@reyjexter
Created September 7, 2013 19:56
Show Gist options
  • Save reyjexter/6478736 to your computer and use it in GitHub Desktop.
Save reyjexter/6478736 to your computer and use it in GitHub Desktop.
/**
* Wait for new notification socket
*/
def waitForNotification = WebSocket.using[JsValue] { request =>
val iteratee = Promise[Iteratee[JsValue, Unit]]()
val enumerator = Concurrent.unicast[JsValue](onStart = { clientChannel =>
iteratee.success(Iteratee.foreach[JsValue] {
json => {
Logger.debug("== Enumerator called ==")
Logger.debug("json: " + json.toString)
val action = (json \ "action").as[String]
val data = (json \ "data").as[JsValue]
Logger.debug(">> action: " + action)
executeAction(action, data, clientChannel)
}
}.mapDone {
_ => {
Logger.debug("disconnected client channel")
NotificationActor.disconnect(clientChannel)
}
})
})
(Iteratee.flatten(iteratee.future), enumerator)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment