This is a utility class to help you set up signals3 to transport events between the default execution context (Threading.defaultContext) and other custom contexts, and a secondary execution context usually associated with GUI. On platforms such as Android or JavaFX, a Runnable task that involves changes to the app's GUI requires to be run in a special execution context - otherwise it will either not work, will result in errors, or may even crash the app. Your platform should provide you with a method which you can call with the given task to execute it properly. If that method is of the type Runnable => Unit (or if you can wrap it in a function of this type) you can pass it to UiDispatchQueue in the app's initialization code. Later, UiDispatchQueue will let you use extension methods .onUi on event streams and signals. They work exactly like .foreach but they will run the subscriber code in your GUI platform execution context.
Executes a task on this queue. You can use this to execute a piece of code on another dispatch queue than the one default to the parent code block, i.e.
Executes a task on this queue. You can use this to execute a piece of code on another dispatch queue than the one default to the parent code block, i.e.
... // running on Threading.defaultContext
UiDispatchQueue.Ui {
... // this will run on the UI thread
}
...
Type parameters
A
the type of the task result
Value parameters
task
an operation to perform on this queue.
Attributes
Returns
a closeable future which will finish with the result of the task
Prepares for the execution of a task. Returns the prepared execution context. The recommended implementation of prepare is to return this.
Prepares for the execution of a task. Returns the prepared execution context. The recommended implementation of prepare is to return this.
This method should no longer be overridden or called. It was originally expected that prepare would be called by all libraries that consume ExecutionContexts, in order to capture thread local context. However, this usage has proven difficult to implement in practice and instead it is now better to avoid using prepare entirely.
Instead, if an ExecutionContext needs to capture thread local context, it should capture that context when it is constructed, so that it doesn't need any additional preparation later.
Attributes
Deprecated
[Since version 2.12.0] preparation of ExecutionContexts will be removed