Emitter

https://in-kotlin.com/design-patterns/observer/

Uses CopyOnWriteArrayList internally so that concurrent calls to attach from multiple threads cannot lose subscriptions, and emit iteration is safe even if a subscriber calls detach during the callback. Subscribers are expected to attach before simulation starts and detach after it ends; dynamic mid-run subscription is not supported.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard

Properties

Link copied to clipboard
Link copied to clipboard

Returns true if emissions are turned on AND there is at least one active subscriber listening to this emitter. Useful for avoiding expensive object creation if no one is listening.

Functions

Link copied to clipboard
fun attach(callback: (newValue: TType) -> Unit): Emitter.Connection
Link copied to clipboard
fun detach(connection: Emitter.Connection)
Link copied to clipboard
fun emit(newValue: TType)