(1) DB에서 값을 가져 오려는 Action.async가 필요합니다. DB를 사용할 수없는 경우, 다른 자원에 연결을 시도하고 (2) 거기에서 값을 가져옵니다. 내가 사용하고있는 두 가지 리소스가 Future를 반환하기 때문에 "recover"키워드로 구분합니다.scala.concurrent.Future [play.api.mvc.Result] required : play.api.mvc.Result
def show(url: String) = Action.async { implicit request: Request[AnyContent] =>
println("url: " + url)
val repositoryUrl = RepositoryUrl(url)
val repositoryId = RepositoryId.createFromUrl(url)
// Listing commits from the DB
val f: Future[Seq[Commit]] = commit.listByRepository(repositoryId.toString())
f.map { f: Seq[Commit] =>
val json = JsObject(Seq(
"project URL" -> JsString(url),
"list of commits" -> Json.toJson(f)))
Ok(json)
}.recover {
case e: scala.concurrent.TimeoutException =>
// InternalServerError("timeout")
// Listing commits from the Git CLI
val github = rules.GitHub(repositoryUrl)
val seq: Future[Seq[Commit]] = github.listCommits
seq.map { seq: Seq[Commit] =>
val json = JsObject(Seq(
"project URL" -> JsString(url),
"list of commits" -> Json.toJson(seq)))
Ok(json)
}
}
}
내가 선 seq.map { seq: Seq[Commit] =>
에 오류 type mismatch; found : scala.concurrent.Future[play.api.mvc.Result] required: play.api.mvc.Result
을 얻고있다 : 그것은 최선의 방법입니다 ..... 그러나 복구 {} 내부의 문이 형식 불일치 오류가 있는지 확실하지 않다. 내 미래가 실패하면 어떻게 다른 결과를 얻을 수 있습니까?
감사합니다. recoverWith
이 결과로 미래를 기대하면서