Get the status of a std::future

You are correct, and apart from calling wait_until with a time in the past (which is equivalent) there is no better way. You could always write a little wrapper if you want a more convenient syntax: template<typename R> bool is_ready(std::future<R> const& f) { return f.wait_for(std::chrono::seconds(0)) == std::future_status::ready; } N.B. if the function is deferred this … Read more

Scala’s “for comprehension” with futures

First about for comprehension. It was answered on SO many many times, that it’s an abstraction over a couple of monadic operations: map, flatMap, withFilter. When you use <-, scalac desugars this lines into monadic flatMap: r <- monad into monad.flatMap(r => … ) it looks like an imperative computation (what a monad is all … Read more

Dartlang wait more than one future

You can use Future.wait to wait for a list of futures: import ‘dart:async’; Future main() async { var data = []; var futures = <Future>[]; for (var d in data) { futures.add(d.loadData()); } await Future.wait(futures); } DartPad example

Transform Java Future into a CompletableFuture

If the library you want to use also offers a callback style method in addition to the Future style, you can provide it a handler that completes the CompletableFuture without any extra thread blocking. Like so: AsynchronousFileChannel open = AsynchronousFileChannel.open(Paths.get(“/some/file”)); // … CompletableFuture<ByteBuffer> completableFuture = new CompletableFuture<ByteBuffer>(); open.read(buffer, position, null, new CompletionHandler<Integer, Void>() { @Override … Read more