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

Confusion about threads launched by std::async with std::launch::async parameter

The std::async (part of the <future> header) function template is used to start a (possibly) asynchronous task. It returns a std::future object, which will eventually hold the return value of std::async‘s parameter function. When the value is needed, we call get() on the std::future instance; this blocks the thread until the future is ready and …

Read more

Why Future.sequence executes my futures in parallel rather than in series?

The futures are running concurrently because they have been started concurrently :). To run them sequentially you need to use flatMap: Future { println(“startFirst”); Thread.sleep(3000); println(“stopFirst”) }.flatMap{ _ => Future { println(“startSecond”); Thread.sleep(1000); println(“stopSecond”) } } Future.sequence just turns Seq[Future[T]] => Future[Seq[T]] which means gather results of all already started futures and put it in …

Read more