I have method
def seqAll: Future[Seq[User]] = dbConfig.run(users.result) def getAll: Seq[User] = Users.seqAll.map(a=>a) second method actually returns Future[Seq[User]], but I want it to be just Seq[User]. How can I achieve that?
I have method
def seqAll: Future[Seq[User]] = dbConfig.run(users.result) def getAll: Seq[User] = Users.seqAll.map(a=>a) second method actually returns Future[Seq[User]], but I want it to be just Seq[User]. How can I achieve that?
You can use Await.result but that means making the Future blocking and not asynchronous which takes away the point of using a future. Of course, blocking might not be a problem for you.
If you do want to get the result in a non-blocking way you do
Users.seqAll.map(a=>a) onComplete { case Success(result) => // use result for something case Failure(t) => // Handle error } With Await.result:
import scala.concurrent.Await import scala.concurrent.duration.DurationInt def getAll: Seq[User] = Await.result(seqAll, 5.seconds)