Created
May 26, 2016 18:55
-
-
Save Groostav/4a9252d17700f7aabe0e21da10fb52a8 to your computer and use it in GitHub Desktop.
empowerops implementation of `runImmediately` for javafx
This file contains hidden or 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 class SyncingUtilities { | |
//... | |
public static void runImmediatelyOnFXThread(Action actionToRunOnJavaFXThread) { | |
if (BootstrappingUtilities.isFXApplicationThread()) { | |
actionToRunOnJavaFXThread.run(); | |
return; | |
} | |
Ref<Throwable> exceptionRaisedByJavaFXAction = new Ref<>(null); | |
CountDownLatch latch = new CountDownLatch(1); | |
Platform.runLater(() -> { | |
try { | |
actionToRunOnJavaFXThread.run(); | |
} | |
catch (Exception | AssertionError error) { | |
exceptionRaisedByJavaFXAction.target = error; | |
} | |
finally { | |
latch.countDown(); | |
} | |
}); | |
try { | |
latch.await(); | |
} | |
catch (InterruptedException e) { | |
throw new RuntimeException(e); | |
} | |
if (exceptionRaisedByJavaFXAction.target != null) { | |
ExceptionUtilities.throwAsUnchecked(exceptionRaisedByJavaFXAction.target); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment