5

In my program on Play 2.0.4 I had this piece of code:

val channel = Enumerator.imperative[JsValue](onStart = self ! NotifyJoin(username))

and now it says that imperative is deprecated, and the API says that I should use unicast or broadcast instead. I tend to use unicast since in my code the channel was unicast. So I make like

val channel = Concurrent.unicast[JsValue](onStart = self ! NotifyJoin(username))

But it does not work.. looks like that unicast wants something else. I cannot figure it out - there is no more info in the API... does anyone know what to do here?

UPDATE:

Started a discussion in Play Framework user group. Turns out to be a pretty common problem among developers, who are knew to the paradigm. Will hope the documentation is going to be improved.

4

2 回答 2

3

APIConcurrent.unicast是:

unicast[E](onStart: (Channel[E]) ⇒ Unit, onComplete: ⇒ Unit, onError: (String, Input[E]) ⇒ Unit): Enumerator[E]

APIConcurrent.broadcast是:

broadcast[E]: (Enumerator[E], Channel[E])

您可以在您的应用程序中访问 API:

http://localhost:9000/@documentation/api/scala/index.html#play.api.libs.iteratee.Concurrent$
于 2013-01-14T03:57:29.297 回答
0

使用单播的示例:

// here is an enumerator that returns a chunk to the channel
val outEnumerator = Concurrent.unicast[JsValue] { channel =>
    val data = Json.obj("data" -> 12345)
    channel.push(data)
}

使用旧 Enumerator.imperative 的替代方法是使用 generateM:

val out = Enumerator.generateM[JsValue] {
    Promise.timeout( {
        Some(Json.obj("data" -> 12345))
    }, 100, TimeUnit.MILLISECONDS )
}

在这里,我们使用超时生成一个重复值。这个枚举器永远重复,尽管 generateM 允许您返回 None 以指示何时完成。

于 2013-04-18T14:03:39.847 回答