测试这个我可以看到它的工作原理:
def twoHtmlFutures = Action { request =>
val async1 = as1.index(embed = true)(request) // Future[Result]
val async2 = as2.index(embed = true)(request) // Future[Result]
val async1Html = async1.flatMap(x => Pagelet.readBody(x)) // Future[Html]
val async2Html = async2.flatMap(x => Pagelet.readBody(x)) // Future[Html]
val source1 = Source.fromFuture(async1Html) // Source[Html, NotUsed]
val source2 = Source.fromFuture(async2Html) // Source[Html, NotUsed]
val merged = source1.merge(source2) // Source[Html, NotUsed]
Ok.chunked(merged)
}
Run Code Online (Sandbox Code Playgroud)
但试图将其纳入For Comprehension并不适合我.这是我试过的:
def twoHtmlFutures2 = Action.async { request =>
val async1 = as1.index(embed = true)(request) …Run Code Online (Sandbox Code Playgroud)