kotlin-flow-extensions / hu.akarnokd.kotlin.flow / BehaviorSubject

BehaviorSubject

@FlowPreview class BehaviorSubject<T> : AbstractFlow<T>, SubjectAPI<T>

Caches one item and replays it to fresh collectors.

Constructors

<init>

BehaviorSubject()

Constructs an empty BehaviorSubject.

BehaviorSubject(initialValue: T)

Constructs a BehaviorSubject with an initial value to emit to collectors.

Functions

collectSafely

suspend fun collectSafely(collector: FlowCollector<T>): Unit

Accepts a collector and emits the latest (if available) value and any subsequent value received by this BehaviorSubject until the BehaviorSubject gets terminated.

collectorCount

fun collectorCount(): Int

Returns the number of collectors waiting for data.

complete

suspend fun complete(): Unit

Signal current and future collectors that no further values will be coming.

emit

suspend fun emit(value: T): Unit

Emit a value to all current collectors when they are ready.

emitError

suspend fun emitError(ex: Throwable): Unit

Signal an exception to all current and future collectors when they are ready.

hasCollectors

fun hasCollectors(): Boolean

Returns true if this subject has collectors waiting for data.