1

I am trying the application in - 30 minutes to make realtime paint - youtube video. I have tried to follow it as closely as possible and after all that just as when I thought it was completed, I get deprecation warnings!

I am trying to learn scala & play. Tried Googling a bit with no help; I just do not know where to start looking in order solve the problem.

The relevant code snippet comes around Minute:26 in the video. A copy here as well:

val hubEnum = Enumerator.imperative[JsValue]()
val hub = Concurrent.hub[JsValue](hubEnum)
var counter = 0

def index = Action {
  Ok(views.html.index("Your new application is ready."))
}

def stream = WebSocket.async[JsValue] { request =>
  var out = hub.getPatchCord()
  counter += 1
  var pid = counter
  var in = Iteratee.foreach[JsValue](_ match {
    case message: JsObject => {
      hubEnum push(message ++ JsObject(Seq("pid" -> JsNumber(pid))))
    }
  })
  Promise.pure((in, out))
}

The error:

[warn] /home/user/devpt/testpaint/app/controllers/Application.scala:12: class PushEnumerator in package iteratee is deprecated: use Concurrent.broadcast instead
[warn]   val hubEnum = Enumerator.imperative[JsValue]()
[warn]       ^
[warn] /home/user/devpt/testpaint/app/controllers/Application.scala:12: method imperative in object Enumerator is deprecated: use Concurrent.broadcast instead
[warn]   val hubEnum = Enumerator.imperative[JsValue]()
[warn]                            ^
[warn] /home/user/devpt/testpaint/app/controllers/Application.scala:13: trait Hub in object Concurrent is deprecated: use Concurrent.broadcast instead
[warn]   val hub = Concurrent.hub[JsValue](hubEnum)
[warn]       ^
[warn] /home/user/devpt/testpaint/app/controllers/Application.scala:13: method hub in object Concurrent is deprecated: use Concurrent.broadcast instead
[warn]   val hub = Concurrent.hub[JsValue](hubEnum)
[warn]                        ^
4

1 回答 1

2

Concurrent.broadcast是管理广播的新方法。它在 Tuple2 中返回一个 Enumerator 和一个 Channel。

Channel是您可以通过push方法发送消息的地方。

Enumerator是客户端获取发送到 Channel 的消息的方式,您可以通过Iteratee对其进行处理。

新的Websocket-Chat 示例应用程序显示了使用情况,下载它,您可以通过 Play 中广播消息的新方式替换相关代码位。

于 2013-06-12T15:57:00.753 回答