SyncEventMessenger

Synchronous messenger for generic events. It allows event publishing and also handles the subscription of event listeners.

Important: This is a Public Preview API. It may be changed or removed at any time.

Constructors

Link copied to clipboard

Functions

Link copied to clipboard
open override fun publish(event: T)

Publishes an event of the given T type.

Link copied to clipboard
open override fun register(listener: EventListener<T>)

Registers EventListener which will be notified about published events.

Link copied to clipboard
open override fun unregister(listener: EventListener<T>)

Unregisters the given EventListener.

Extensions

Link copied to clipboard
suspend fun <T : Event> EventChannel<T>.awaitEvent(awaitedEvent: T): T

Waits till provided event appears in the EventChannel

Link copied to clipboard
fun <T : Event> EventChannel<T>.registerOneShotListener(filter: (T) -> Boolean = { true }, block: (T) -> Unit): AutoCloseable

Registers EventListener that will be called only one time and only when given condition is met. Optional filter can be used to make the listener triggered only for certain events based on provided criteria. By default, all events are accepted. Once the listener is triggered, it will remove itself from this EventChannel automatically.