Map the Exception of a failed Future

There is also: f recover { case cause => throw new Exception(“Something went wrong”, cause) } Since Scala 2.12 you can do: f transform { case s @ Success(_) => s case Failure(cause) => Failure(new Exception(“Something went wrong”, cause)) } or f transform { _.transform(Success(_), cause => Failure(new Exception(“Something went wrong”, cause)))}

Scala waiting for sequence of futures

One common approach to waiting for all results (failed or not) is to “lift” failures into a new representation inside the future, so that all futures complete with some result (although they may complete with a result that represents failure). One natural way to get that is lifting to a Try. Twitter’s implementation of futures … Read more

Differences between Futures in Python3 and Promises in ES6

In both Python and ES6, await/async are based on generators. Is it a correct to think Futures are the same as Promises? Not Future, but Python’s Task is roughly equivalent to Javascript’s Promise. See more details below. I have seen the terms Task, Future and Coroutine used in the asyncio documentation. What are the differences … Read more

Traversing lists and streams with a function returning a future

I cannot answer it all, but i try on some parts: Is there some reason that the “most asynchronous” behavior—i.e., don’t consume the collection before returning, and don’t wait for each future to complete before moving on to the next—isn’t represented here? If you have dependent calculations and a limited number of threads, you can … Read more

In what cases does Future.get() throw ExecutionException or InterruptedException

ExecutionException and InterruptedException are two very different things. ExecutionException wraps whatever exception the thread being executed threw, so if your thread was, for instance, doing some kind of IO that caused an IOException to get thrown, that would get wrapped in an ExecutionException and rethrown. An InterruptedException is not a sign of anything having gone … Read more