What is the best way to construct a completed future in Java? I have implemented my own CompletedFuture below, but was hoping something like this that already exist
CompletedFuture
FutureTask ft = new FutureTask<>(() -> "foo"); ft.run(); System.out.println(ft.get());
will print out "foo";
You can also have a Future that throws an exception when get() is called:
FutureTask ft = new FutureTask<>(() -> {throw new RuntimeException("exception!");}); ft.run();