5

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?

1

2 Answers 2

6

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 } 
Sign up to request clarification or add additional context in comments.

Comments

1

With Await.result:

import scala.concurrent.Await import scala.concurrent.duration.DurationInt def getAll: Seq[User] = Await.result(seqAll, 5.seconds) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.