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

ReplaySubject

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

Caches and replays some or all items to collectors.

Constructors

<init>

ReplaySubject()

Creates a ReplaySubject with an unbounded internal buffer caching all values received via emit.

ReplaySubject(maxSize: Int)

Creates a ReplaySubject that caches at most maxSize values to be replayed to late collectors.

ReplaySubject(maxTime: Long, unit: TimeUnit)

Creates a ReplaySubject that caches values at most for the given maxTime real-time duration and replays those upfront to late collectors.

ReplaySubject(maxSize: Int, maxTime: Long, unit: TimeUnit)

Creates a ReplaySubject that caches at most maxSize values at most for the given maxTime real-time duration and replays those upfront to late collectors.

ReplaySubject(maxSize: Int, maxTime: Long, unit: TimeUnit, timeSource: (TimeUnit) -> Long)

Creates a ReplaySubject that caches at most maxSize values at most for the given maxTime duration (measured via the custom timeSource) and replays those upfront to late collectors.

Functions

collectSafely

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

Accepts a collector and emits the cached values upfront and any subsequent value received by this ReplaySubject until the ReplaySubject gets terminated.

collectorCount

fun collectorCount(): Int

Returns the current number of collectors.

complete

suspend fun complete(): Unit

Indicate no further items will be produced.

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 Throwable to the collector.

hasCollectors

fun hasCollectors(): Boolean

Returns true if this PublishSubject has any collectors.