score:-1

Accepted answer

You cannot "get" a future without blocking. if you want to wait for a Future to complete then you must block.

What you can do is map a Future into another Future:

val futureDoc: Future[BSONDocument] = ...
val futureList = futureDoc map { doc => docToList(doc) }

Eventually, you'll hit a point where you've combined, mapped, recovered, etc. all your futures and want something to happen with the result. This is where you either block, or establish a handler to do something with the eventual result:

val futureThing: Future[Thing] = ...

//this next bit will be executed at some later time,
//probably on a different thread
futureThing onSuccess {
  case thing => doWhateverWith(thing)
}

score:0

Not sure about your exact use-case (showing some more code would help), but it might be useful to convert from List[Future[BSONDocument]] to one Future[List[BsonDocument]], which you can then more easily onSuccess or map on, you can do that via:

val futures: List[Future[A]] = List(f1, f2, f3)
val futureOfThose: Future[List[A]] = Future.sequence(futures)

Related Query

More Query from same tag