Last active
December 10, 2015 01:38
-
-
Save atamborrino/4361180 to your computer and use it in GitHub Desktop.
Play 2.1 - Using Concurrent.PatchPannel with a Future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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