Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Async Task Execution

Edvin Syse edited this page Jan 9, 2016 · 8 revisions

WikiDocumentationAsync Task Execution

Async Task Execution

A responsive UI needs to make sure that no long running tasks are perform on the UI thread. In a Tornado FX application, long running tasks are typically defined in Controllers. To ensure work is performed in the correct thread, you can use the background function:

background {
    customerController.listCustomers()
} ui {
    customerTable.items = it
}

The background function simply wraps your code in a JavaFX Task and executes it. ui is an extension function defined on Task that will make sure the supplied code will run on the UI thread once the task completes. The parameter supplied to ui is the Task result.

If an error occurs in the background operation, the default Error Handler is called.

You can ofcourse just catch and handle any error directly in the background operation, or install a different error handler by calling the Task#setOnFailed function. Infact, you can augment your Task in all the usual ways the Task interface allows for.

Next: Extension Functions

Clone this wiki locally