May 2015
Intermediate to advanced
274 pages
5h 11m
English
Let's define a WebSocket connection, which accepts strings and sends back the reverse of a string using Iteratee:
def websocketBroadcast = WebSocket.using[String] {
request =>
val (out, channel) = Concurrent.broadcast[String]
val in = Iteratee.foreach[String] {
word => channel.push(word.reverse)
}
(in, out)
}The WebSocket.using method creates a WebSocket of a specific type using an Iteratee (inbound channel) and its corresponding enumerator (outbound channel). In the preceding code snippet, we return a tuple of the Iteratee in and the Enumerator out.
The Concurrent object is also a helper, which provides utilities to use Iteratees, Enumerators, and Enumeratees concurrently. The broadcast[E] method creates an Enumerator ...
Read now
Unlock full access