UiDispatchQueue

io.github.makingthematrix.signals3.ui.UiDispatchQueue
See theUiDispatchQueue companion object
final class UiDispatchQueue(runUiWith: Runnable => Unit) extends DispatchQueue

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
trait ExecutionContext
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def execute(runnable: Runnable): Unit

Attributes

Definition Classes
ExecutionContext

Inherited methods

def apply[A](task: => A): CloseableFuture[A]

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

Inherited from:
DispatchQueue
def hasRemainingTasks: Boolean

If the queue is a limited one, some tasks may need to wait before being executed.

If the queue is a limited one, some tasks may need to wait before being executed.

Attributes

Returns

true if there is a task waiting in the queue to be executed after one of the current one finishes, false otherwise.

Inherited from:
DispatchQueue
override def reportFailure(t: Throwable): Unit

Value parameters

t
  • the error that occured when executing a task on this queue.

Attributes

Todo

Currently not used. Left here as a reminder that in the future we may provide logging functionality.

Definition Classes
DispatchQueue -> ExecutionContext
Inherited from:
DispatchQueue

Deprecated and Inherited methods

def prepare(): ExecutionContext

Attributes

Deprecated
[Since version 2.12.0] preparation of ExecutionContexts will be removed
Inherited from:
ExecutionContext

Inherited fields

val name: String

Attributes

Inherited from:
DispatchQueue