| 480 | } |
| 481 | |
| 482 | public static <T> CompletableFuture<T> runAsyncTask(Callable<T> task) { |
| 483 | Task<T> jfxTask = new Task<T>() { |
| 484 | @Override |
| 485 | protected T call() throws Exception { |
| 486 | return task.call(); |
| 487 | } |
| 488 | }; |
| 489 | |
| 490 | CompletableFuture<T> ret = new CompletableFuture<T>(); |
| 491 | |
| 492 | jfxTask.setOnSucceeded(event -> ret.complete(jfxTask.getValue())); |
| 493 | jfxTask.setOnFailed(event -> ret.completeExceptionally(jfxTask.getException())); |
| 494 | jfxTask.setOnCancelled(event -> ret.cancel(false)); |
| 495 | |
| 496 | threadPool.execute(jfxTask); |
| 497 | |
| 498 | return ret; |
| 499 | } |
| 500 | |
| 501 | public void runProgressTask(String labelText, Consumer<DoubleConsumer> task) { |
| 502 | runProgressTask(labelText, task, null, null); |