【发布时间】:2011-11-11 09:10:40
【问题描述】:
我不确定这是否没有按预期工作,这只是我感到困惑。
我想做的是异步延迟一个动作,我和await(int millis)好像可以成为朋友了。
会发生什么:
1. Application.index 显示一个向Application.something 发送 POST 的表单。
app/controllers/Application.java
public static void index() {
render();
}
app/views/Application/index.html
#{form @Application.something()}
<input type="submit">
#{/form}
2. Application.something 完成它的工作,然后链接回 index。
app/controllers/Application.java
public static void something() {
await(500);
// Here be business
index();
}
3. Play 引发应用程序错误:“模板 Application/something.html 不存在”。
所以当Application.index 中的Application.something 执行被暂停/恢复后在Application.index 中调用render() 时,它会尝试呈现Application.something 的模板,这当然不存在。
如果我删除 await(500) 一切正常(发出 302 并按预期呈现 index)。
我可以强制重定向
redirect("/");
得到我想要的结果,但这感觉很难看。
我也可以设置
request.action = "Application.index";
在await 和Application.index 中的渲染之后手动按预期工作(实际上,Controller.template() 中的魔法工作)。
所以基本上,一切正常吗?我不得不在await 之后使用字符串,而不是方法调用,还是有点不对劲?
干杯, 托比亚斯。
【问题讨论】:
标签: playframework continuation async-await