在我的 Play 2.0.4 程序中,我有这段代码:
val channel = Enumerator.imperative[JsValue](onStart = self ! NotifyJoin(username))
现在它说
imperative
已弃用,API 说我应该使用 unicast
或 broadcast
反而。我倾向于使用 unicast
因为在我的代码中 channel
是单播的。所以我喜欢val channel = Concurrent.unicast[JsValue](onStart = self ! NotifyJoin(username))
但它不起作用..看起来像
unicast
想要别的东西。我无法弄清楚 - API 中没有更多信息......有谁知道在这里做什么?更新:
在 Play Framework 用户组中开始讨论。事实证明,在熟悉范式的开发人员中,这是一个非常普遍的问题。希望文档能得到改进。
最佳答案
Concurrent.unicast
的 API是:
unicast[E](onStart: (Channel[E]) ⇒ Unit, onComplete: ⇒ Unit, onError: (String, Input[E]) ⇒ Unit): Enumerator[E]
Concurrent.broadcast
的 API是:broadcast[E]: (Enumerator[E], Channel[E])
您可以通过以下网址访问应用程序中的 API:
http://localhost:9000/@documentation/api/scala/index.html#play.api.libs.iteratee.Concurrent$
关于PlayFramework 2.0.x -> 2.1-RC 迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14141408/