BehaviorSubject

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

Caches one item and replays it to fresh collectors.

Constructors

BehaviorSubject
Link copied to clipboard
fun BehaviorSubject()
Constructs an empty BehaviorSubject.
BehaviorSubject
Link copied to clipboard
fun <T> BehaviorSubject(initialValue: T)
Constructs a BehaviorSubject with an initial value to emit to collectors.

Functions

collect
Link copied to clipboard
suspend override fun collect(collector: FlowCollector<T>)
collectorCount
Link copied to clipboard
open override fun collectorCount(): Int
Returns the number of collectors waiting for data.
collectSafely
Link copied to clipboard
open suspend override fun collectSafely(collector: FlowCollector<T>)
Accepts a collector and emits the latest (if available) value and any subsequent value received by this BehaviorSubject until the BehaviorSubject gets terminated.
complete
Link copied to clipboard
open suspend override fun complete()
Signal current and future collectors that no further values will be coming.
emit
Link copied to clipboard
open suspend override fun emit(value: T)
Emit a value to all current collectors when they are ready.
emitError
Link copied to clipboard
open suspend override fun emitError(ex: Throwable)
Signal an exception to all current and future collectors when they are ready.
hasCollectors
Link copied to clipboard
open override fun hasCollectors(): Boolean
Returns true if this subject has collectors waiting for data.

Properties

value
Link copied to clipboard
val value: T
Returns a single value the Subject currently has or throw "No value" if no such value exists.
valueOrNull
Link copied to clipboard
val valueOrNull: T?
Returns a single value the Subject currently has or null if no such value exists.