Last active
November 28, 2015 22:17
-
-
Save Groostav/2944cb86e87848399924 to your computer and use it in GitHub Desktop.
snippit of our Platform.runImmediately method
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, boolean exitOnInterrupt) { | |
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) { | |
Log.warning("interrupted"); | |
if(exitOnInterrupt) break; else continue; | |
} | |
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