【问题标题】:How to handle multiple async requests for a Mustache template on Scalatra如何在 Scalatra 上处理 Mustache 模板的多个异步请求
【发布时间】:2014-05-20 11:14:55
【问题描述】:

我有一个使用 Mustache 模板在 Scalatra 上运行的简单 Web 应用程序。为了呈现页面,我需要向 Web 服务发出三个单独的请求。 Akka approach shown in Scalatra guides 是要走的路吗?我需要引入链接或闩锁吗?或者是否可以在结果到达时将结果传递给 Mustache 模板?

【问题讨论】:

    标签: 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))
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-22
        • 2018-05-27
        • 2019-03-26
        • 1970-01-01
        • 1970-01-01
        • 2014-04-10
        • 2017-08-21
        • 2018-06-12
        相关资源
        最近更新 更多