On Thu, May 22, 2014 at 1:37 AM, xx...@twitter.com wrote:
It seems that Future.handle takes PartialFunction[Throwable, B], while Future.rescue takes PartialFunction[Throwable, Future[B]]. Besides this, is
there any other difference between them? Any heuristic when we should use one or the other? Thanks a lot!
You’re talking about Twitter’s implementation of Future. The equivalent to Scala’s Future would be recover and recoverWith.
The difference between them is the same difference as between map and flatMap. In the context of a Future, flatMap and recoverWith specify a result that also has to be processed async - i.e. when you’re done, continue with this piece of processing that is also a Future and use its result as the result of this future (i.e. flattening what would be aFuture[Future[T]] into a Future[T]).
So it's pretty clear on which one you should use, depending on the fallback result you've got.