Skip to content

Instantly share code, notes, and snippets.

@atamborrino
Last active December 10, 2015 01:38
Show Gist options
  • Save atamborrino/4361180 to your computer and use it in GitHub Desktop.
Save atamborrino/4361180 to your computer and use it in GitHub Desktop.
Play 2.1 - Using Concurrent.PatchPannel with a Future
def stream = WebSocket.using[JsValue] { req =>
val promiseIn = promise[Iteratee[JsValue, Unit]]
val out = Concurrent.patchPanel[JsValue] { patcher =>
val in = Iteratee.foreach[JsValue] { json =>
val topic = // read json and get the topic that the user want to subscribe to
val streamForThisTopic = // get the corresponding stream (enumerator)
patcher.patchIn(streamForThisTopic)
} mapDone { _ => println("Disconnected") }
promiseIn.success(in)
}
(Iteratee.flatten(in.future), out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment