1

プレイスリックを使用しています。play-slick DBaction 内で未来を返そうとしていますが、失敗します:

def test = DBAction(parse.json){ implicit request =>
      scala.concurrent.Future {
        NotFound(Json.obj("error" -> "some error"))
      } 
}

[error]  found   : scala.concurrent.Future[play.api.mvc.Result]
[error]  required: play.api.mvc.Result

この未来を取り戻すにはどうすればいいですか?Async { } は 2.3 で廃止され、DBAction().async (ドキュメントでは将来の通常の play-Action に使用するように指示されています) は利用できないようです。

4

1 に答える 1

1

Future.firstCompleteOf( DB call , timeout ) を使用しているため、最近同じ質問/問題がありましたが、代わりに DB.withSession を使用するとうまくいくようです。

したがって、コントローラーのアクションは引き続き Action.async ブロック内にとどまり、Future は次のようになります

Future.firstCompleteOf(Seq(Future( 
    DB.withSession {implicit session => MyTable.findById(id) } ), timeoutFuture) ).map { 
      case Whatever => … 
}.recoverWith {
  case Whatever => … 
}
于 2014-08-18T08:26:17.600 に答える