Thanks to Java SE 8's CompletableFuture it is possible to do low-level reactive programming style in Java. With JavaFX this is a bit cumbersome, as there is not Executor for JavaFX.
I like to propose to add the following code to the Platform class:
```
public static final Executor JAVA_FX = Platform::runAsJavaFX;
public static final void runAsJavaFX(final Runnable runnable) {
if (Platform.isFxApplicationThread())
runnable.run();
else
Platform.runLater(runnable);
}
```
This makes it pretty simple and readable to use CompletableFuture with Java FX, hence allowing totally simple background tasks done by the Java SE's shared thread pool:
```
CompletableFuture.supplyAsync(backgroundTask).thenAcceptAsync(javaFxTask, JAVA_FX);
```
I like to propose to add the following code to the Platform class:
```
public static final Executor JAVA_FX = Platform::runAsJavaFX;
public static final void runAsJavaFX(final Runnable runnable) {
if (Platform.isFxApplicationThread())
runnable.run();
else
Platform.runLater(runnable);
}
```
This makes it pretty simple and readable to use CompletableFuture with Java FX, hence allowing totally simple background tasks done by the Java SE's shared thread pool:
```
CompletableFuture.supplyAsync(backgroundTask).thenAcceptAsync(javaFxTask, JAVA_FX);
```