EventObservable

An implementation of Observable that emits updates to its observers when triggered manually via the emit method. The observed value is always Unit. A standard it.unibo.alchemist.model.observation.MutableObservable of Unit is not the answer to an observable emitter, because of observable idempotency.

This class allows multiple observers to register for notifications, and provides the ability to manually emit updates to those observers.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open override val current: Unit

The current value: while observed, the latest value published; otherwise, a freshly computed one. Observables holding their own state may read it directly.

Link copied to clipboard

Whether any callback is currently registered.

Link copied to clipboard
override val observerCount: Int

How many callbacks are currently registered.

Functions

Link copied to clipboard
fun <T> Observable<Option<T>>.currentOrNull(): T?

Retrieves the current value of the observable if present, or null if no value is available.

Link copied to clipboard
open override fun dispose()

Unregisters every callback registered with this observable.

Link copied to clipboard
fun emit()

Triggers the emission of a notification from this observable notifying all of its observers.

Link copied to clipboard
open override fun <S> map(transform: (Unit) -> S): Observable<S>

Transforms the current observable into a new observable by applying the specified transformation function to its emitted values.

Link copied to clipboard
open override fun <O, R> mergeWith(other: Observable<O>, merge: (Unit, O) -> R): Observable<R>

Combines the current observable with another observable, producing a new observable that emits values derived by applying the provided merge function to the current values of both observables.

Link copied to clipboard
open override fun onChange(notifyOnRegistration: Boolean = true, callback: (Unit) -> Unit): Disposable

Registers callback to be invoked with every new value of this observable, and right away with the current one if notifyOnRegistration.

Link copied to clipboard
fun <T, R> Observable<T>.switchMap(transform: (T) -> Observable<R>): Observable<R>

Maps the current value of this Observable to an inner observable through transform, and mirrors the inner observable of the most recent value only: whenever this observable emits, the previous inner observable is unsubscribed and the new one is followed.