PushEnumerator在Play Framework2.1-RC中被弃用。文档告诉我改用Concurrent.broadcast。但是,我推送的数据依赖于用户,所以我不能将相同的数据广播给每个用户。
换句话说,Concurrent.broadcast将给我一个连接到许多迭代器的枚举器,而我需要许多枚举器连接到许多迭代器。
发布于 2013-04-13 09:38:01
下面是一个使用Concurrent.unicastE的简单示例
// 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]
https://stackoverflow.com/questions/14588218
复制相似问题