Created
November 12, 2013 15:08
-
-
Save svenreimers/7432402 to your computer and use it in GitHub Desktop.
Devoxx Hackergarten Lambda Project Use Lambdas to create a method that retrieves values in a thread safe way from the JavaFX scene graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final <T> Future<T> runFuture(Supplier<T> supplier) { | |
FutureTask<T> futureTask = new FutureTask<>(() -> supplier.get()); | |
Platform.runLater(futureTask); | |
return futureTask; | |
} | |
public static final <T> Optional<T> runFutureValue(Supplier<T> supplier) { | |
Future<T> runFuture = runFuture(supplier); | |
try { | |
return Optional.of(runFuture.get()); | |
} catch (InterruptedException iex) { | |
Thread.currentThread().interrupt(); | |
return Optional.empty(); | |
} catch(ExecutionException ex) { | |
return Optional.empty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment