In Play 2.1, what to use instead of deprecated PushEnumerator

PushEnumerator is deprecated in Play Framework 2.1-RC. The documentation suggests that I use Concurrent.broadcast instead. However, the data that I click depends on the user, so I can not transmit the same data to each user.

In other words, Concurrent.broadcast will provide me with one enumerator that connects to many iterations, while I need many enumerations that connect many iterations.

+8
source share
1 answer

Here is a simple example of using Concurrent.unicast [E]:

// assume the following exist: def readValueAsync(source: MySource): Future[Any] val source: MySource = ... // this is where the meat is: val valueEnumerator = Concurrent.unicast[Any] { (channel: Concurrent.Channel[Any]) => readValueAsync(source) onComplete { case Success(x: Any) => channel.push(x) case Failure(t) => channel.end(t) } } // you can then collect it using an iteratee // since my enumerator never really ends, I only take 10 elements here val result: List[Any] = valueEnumerator through Enumeratee.take(10) run Interatee.getChunks[Any] 
+5
source share

All Articles