Lift:从 Future 内向客户端发送通知
在电梯中,我有一个页面接受一些要上传的文件,然后处理这些文件(大约需要一分钟以上)我不想让用户等待一分钟只是为了看到另一个页面,所以我决定将处理工作放入 Future
对象中。我的最终目标是在处理完成后向用户发送指向结果页面的链接。
这是我的代码的要点:
Futures.future {
doLongLastingProcessing
val linkXml = makeLinkToResults
println("Hey I'm done!")
S.notice(linkXml)
}
我遇到的问题是,在 Future 中完成的任何与 S 相关的东西似乎都不起作用。工作完成,我在控制台中看到“嘿,我完成了”,但没有收到任何通知。
如何向用户发出“完成”通知(即使他们已离开上传页面)?
In lift, I have a page that accepts a few files to be uploaded, and then processes the files (which takes around a minute+) I don't want to make users wait the full minute just to see another page, so I decided to put the processing work into a Future
object. My end goal is to send the user a link to the results page once the processing is done.
Here's the gist of my code:
Futures.future {
doLongLastingProcessing
val linkXml = makeLinkToResults
println("Hey I'm done!")
S.notice(linkXml)
}
The problem I get is that any S-related stuff done within the Future doesn't seem to work. The work finishes and I see the "Hey I'm done" in the console, but get no notice.
How can I get a "completion" notice to the user (even if they've navigated away from the upload page) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该查看 Lift 的 CometActors 并从未来。或者您可能只想完全放弃 Future 并只使用 Actor。
请注意,有一些问题(例如 没有访问
S
),但听起来您的 CometActor 只能返回正常响应。我刚刚查看了 wiki,显然您确实有 访问S.notice< /code> 在您的 CometActor
中。
You should look at Lift's CometActors and sending a message to the appropriate CometActor from the Future. Or you might just want to drop the Future entirely and just use Actors.
Be aware that there are a few gotchas (e.g. not having access to
S
) but it sounds like your CometActor can just return a normal response. I just checked the wiki, and apparently you do have access toS.notice
within your CometActor.这是一篇文章,展示了如何使用彗星演员帖子来完成您的要求
Here is an article that shows how to do what you are asking using comet actors post