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.
Examples:
Android initialization:
import android.os.{Handler, Looper}
import io.github.makingthematrix.signal3.ui.UiDispatchQueue
val handler = new Handler(Looper.getMainLooper)
UiDispatchQueue.setUi(handler.post)
JavaFX initialization:
import javafx.application.Platform
import io.github.makingthematrix.signal3.ui.UiDispatchQueue
UiDispatchQueue.setUi(Platform.runLater)
Usage in all cases:
import io.github.makingthematrix.signal3.ui.UiDispatchQueue.*
signal ! true
signal.onUi { value => ... }
Future { ... }(Ui)
Value parameters
- runUiWith
-
A function from the GUI platform you're working with that will execute a given task in the GUI context
Attributes
- Companion
- object
- Graph
-
- Supertypes