需要在游戏框架示例中继续使用
你能给我一些链接,其中包含如何在游戏框架中使用延续的好例子吗?(除了游戏框架的来源,他们的“样本和测试”和现场文档,已经在那里)
“for dummies”中的任何文档和理论" 格式也受到赞赏。
Can you give me some links with good examples how to use continuations in play framework?(beside source of play framework, their 'samples-and-tests' and on-site doc, already were there)
Any documentation and theory in "for dummies" format are also appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Continuations 主要通过使用通过控制器提供的
await()
方法来工作。 wait 方法可以接受两种不同类型的参数(该方法实际上有 6 个重载,但它们是 2 个主题的简单变体)。第一个是调用 wait 并设置超时。这可以以毫秒为单位,也可以使用表示时间的字符串文字来指定,例如
1s
表示 1 秒等。第二个是使用
Future
对象调用 wait,并且最常用的是 Play 的 java Future 实现,称为 Promise(在 libs.F 中)。当 Promise 实现时,Promise 返回,因为作为 Promise 一部分调用的事件已完成。然而,一个 Promise 可以是多个事件,也可以是多个事件。甚至可以选择 waitAny,以便它只等待多个事件之一返回。因此,这两种方法基本上都会导致事件在未来某个时刻发生。第一个是预先确定的,第二个取决于履行承诺需要多长时间。
继续播放是一种使该事件结构的编码变得更容易的方法。您可以输入一些代码,说明
在幕后,HTTP 线程被释放,以便 Play 可以更高效地处理更多并发请求。当超时或承诺完成时,该方法将继续执行,而无需为再次启动的执行线程编写任何特定处理代码。
从 Play 站点获取代码进行延续,它说
This 实际上结束了执行线程 10 次,并在 1 秒等待后启动一个新线程。从程序员的角度来看,这整个事情是完全透明的,并且允许您直观地构建应用程序,而无需担心创建非阻塞应用程序,因为这一切都由 Play 神奇地处理!
Continuations works mainly by using the
await()
method that is made available through your Controller. The await method can accept two different types of parameter (there are actually 6 overloads of the method, but they are simple variations on the 2 themes).The first is calling await with a timeout. This can be in milliseconds, or can be specified using a String literal expressing the time, e.g.
1s
for 1 second etc.The second is calling await with a
Future
object, and most commonly using Play's implementation of the java Future called Promise (in the libs.F). A Promise returns when the promise is fulfilled, in that the event that is invoked as part of the Promise is completed. However, a Promise can be more than a single event, it can be multiple events. There are even options to say waitAny, so that that it only waits for one of many events to return.So, both approaches basically result in an event happening at some point in the future. The first is predetermined, the second depends on how long it takes for the Promise to be fulfilled.
Play continuations is a way to make the coding of this event structure easier. You can enter some code that says
Behind the scenes, the HTTP thread is released, so that Play can process more concurrent requests more efficiently. And when the timeout or promise is fulfilled, the method continues to execute, without you having to code any specific handling for the thread of execution starting up again.
Taking the code from the Play site for continuations, it says
This actually ends the thread of execution 10 times, and start a new thread after a 1 second wait. This whole thing is completely transparent from a programmers perspective, and allows you to build applications intuitively without worrying about creating non-blocking applications, as this is all magically handled by Play!