Try[Future[T]] will either fail now, or return a future that is guaranteed to produce a value of T.
This might be useful, if an exception is also a possible value and it should be processed rather than fail the entire process.
def download(urls : List[URL]) : Future[Map[URL, Array[Byte]]]
If service is done in this way, if one download fails, the entire process fails.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
When this future is completed, either through an exception, or a value, apply the provided function.
OK. Since "A `Future[Try[T]]` can "succeed" with a `Failure[T]", then there would be no failures for Future[Try[T]], is it true?Let me try one example:val getfriend: Future[Try[String]] = future {try(session.getfriends());}getfriend onCompletion {case Success(flist) => println("Get friends list successfully");case Failure(t) => println("fail to retrieve friends list");}In the above example, the result will always be "Get friends list successfully" even if "flist" itself is a "failure".Then when can "getfriend" get failed?
It will only "succeed" with a Failure if you manually return a Failure. If an exception is not caught, the Future itself will fail.
Is it a good idea to flatten Future[Try[T]]?