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

PublishSubject

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

Multicasts items to any number of collectors when they are ready to receive.

Parameters

Constructors

<init>

PublishSubject()

Multicasts items to any number of collectors when they are ready to receive.

Functions

collectSafely

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

Start collecting signals from this PublishSubject.

collectorCount

fun collectorCount(): Int

Returns the current number of collectors.

complete

suspend fun complete(): Unit

Indicate no further items will be emitted

emit

suspend fun emit(value: T): Unit

Emit the value to all current collectors, waiting for each of them to be ready for consuming it.

emitError

suspend fun emitError(ex: Throwable): Unit

Throw an error on the consumer side.

hasCollectors

fun hasCollectors(): Boolean

Returns true if this PublishSubject has any collectors.