【问题标题】:How to handle multiple async requests for a Mustache template on Scalatra如何在 Scalatra 上处理 Mustache 模板的多个异步请求
【发布时间】:2014-05-20 11:14:55
【问题描述】:
【问题讨论】:
标签:
scala
asynchronous
akka
mustache
scalatra
【解决方案1】:
您想在未来完成时调用渲染方法 (mustache())。所以沿着这些思路:
makeAsyncCall() map (result => mustache("template.mustache", "result" -> result))
【解决方案2】:
这就是我最终使用的。
new AsyncResult {
val animals = for{
r1 <- service.getCats()
r2 <- service.getDogs()
r3 <- service.getPonies()
} yield (r1, r2, r3)
val is = animals map (result => mustache("/template.mustache", "cats" -> result._1, "dogs" -> result._2, "ponies" -> result._3))
}