Skip to content

Instantly share code, notes, and snippets.

@guigarage
Created October 22, 2014 16:22
Show Gist options
  • Save guigarage/eb0cb09a348fcd648601 to your computer and use it in GitHub Desktop.
Save guigarage/eb0cb09a348fcd648601 to your computer and use it in GitHub Desktop.
JavaFX concurreny
ProcessChain.create().
addRunnableInPlatformThread(() -> blockUI()).
addSupplierInExecutor(() -> loadFromServer()).
addConsumerInPlatformThread(d -> updateUI(d)).
onException(e -> handleException(e)).
withFinal(() -> unblockUI()).
run();
Runnable backgroundRunnable = () -> {
try {
data = loadFromServer();
Platform.runLater(() -> {
updateUI(data);
});
} catch(Exception e) {
Platform.runLater(() -> {
handleException(e);
});
} finally {
Platform.runLater(() -> {
unblockUI();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment