I want to get the result of a Future without blocking operations. If I write my code with "await", it works but it is not good for me because it is blocking:
val t: Future[MatchResult[Personne]] = db.getPersonne(userId).map(_.get must beEqualTo(personne))
t.await
I tried to change my code with map
:
val r: Future[MatchResult[Personne]] = db.getPersonne(userId).map(_.get must beEqualTo(personne))
r.map {
case r@isWhatIExpected => r
case isNot => isNot
}
but I have this error:
found : scala.concurrent.Future[org.specs2.matcher.MatchResult[Personne]]
[error] required: org.specs2.specification.create.InterpolatedFragment
Future
context, you cannot get out of it without waiting. However, you can useonComplete
to consume the result when it is ready. – marstranfut.foreach
orfut.map
to continue working with the values of a future. – 0__