-
Notifications
You must be signed in to change notification settings - Fork 272
Async Task Execution
Wiki ▸ Documentation ▸ 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