内の変数の値を変更します。値はmap {}内で変更されましたが、外側のマップでは再び0に戻りました。何か間違っていますか?私は初心者です。Scalaは、私は以下のコードを持って未来の
@Mikelは、将来を非同期で実行するので、変数が変更されている前に、[OK]を(responseStatus +は、「」)が実行されるチャンスがたくさんあるが、これは解決策である
val trxRequest: WSRequest = ws.url(route.transcationRoutes).withHeaders("Accept" -> "application/json")
val futureResponse: Future[WSResponse] = trxRequest.post(Json.obj("trxtype" -> trxType, "trxvariable" -> trxVariable, "account" -> account.toJson))
var responseStatus = 0
//Need to retrieve as future
val futureResult: Future[Any] = futureResponse.map {
response => {
logkey = (LoginKeyUtils.getEncryptedKey(accountId))
session.addSession(accountId -> logkey)
responseStatus = response.status;
println(responseStatus)
}
}
// wait for the result
Await.result(futureResult, 5000 millis)
Ok(responseStatus)
として
Future[Result]
を取るだろう。ここで 'Await'を使うと、メインのスレッドをブロックすることに注意してください。多くの 'Await'を使用する場合、メインスレッドプールがより多くのスレッドを持つように設定する必要がありました。 – jilen