FlowCollector
FlowCollector is used as an intermediate or a terminal collector of the flow and represents an entity that accepts values emitted by the Flow.
This interface should usually not be implemented directly, but rather used as a receiver in a flow builder when implementing a custom operator, or with SAM-conversion. Implementations of this interface are not thread-safe.
Example of usage:
val flow = getMyEvents()
try {
flow.collect { value ->
println("Received $value")
}
println("My events are consumed successfully")
} catch (e: Throwable) {
println("Exception from the flow: $e")
}
Content copied to clipboard
Inheritors
Functions
Link copied to clipboard
Emits all elements from the given channel to this flow collector and cancels (consumes) the channel afterwards. If you need to iterate over the channel without consuming it, a regular for
loop should be used instead.
Collects all the values from the given flow and emits them to the collector. It is a shorthand for flow.collect { value -> emit(value) }
.