I have a simple web app running on Scalatra with Mustache templates. In order to render the page, I need to make three separate requests to web services. Is the Akka approach shown in Scalatra guides the way to go? Do I need to introduce chaining or latches? Or is it possible to pass results to Mustache template as they arrive?
Asked
Active
Viewed 377 times
2 Answers
1
You want to call the render method (mustache()) when your future completes. So something along these lines:
makeAsyncCall() map (result => mustache("template.mustache", "result" -> result))

Casual Jim
- 1,179
- 7
- 13
0
This is what I ended up using.
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))
}

Petteri H
- 11,779
- 12
- 64
- 94