collect

suspend override fun collect(collector: FlowCollector<T>)

Accepts the given collector and emits values into it.

This method can be used along with SAM-conversion of FlowCollector:

myFlow.collect { value -> println("Collected $value") }

Method inheritance

To ensure the context preservation property, it is not recommended implementing this method directly. Instead, AbstractFlow can be used as the base type to properly ensure flow's properties.

Sources

common source
Link copied to clipboard