首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Play 2.1中,使用什么来代替过时的PushEnumerator

在Play 2.1中,使用什么来代替过时的PushEnumerator
EN

Stack Overflow用户
提问于 2013-01-30 01:05:14
回答 1查看 1.3K关注 0票数 8

PushEnumerator在Play Framework2.1-RC中被弃用。文档告诉我改用Concurrent.broadcast。但是,我推送的数据依赖于用户,所以我不能将相同的数据广播给每个用户。

换句话说,Concurrent.broadcast将给我一个连接到许多迭代器的枚举器,而我需要许多枚举器连接到许多迭代器。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-13 09:38:01

下面是一个使用Concurrent.unicastE的简单示例

代码语言:javascript
运行
复制
// 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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14588218

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档