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

Accepts the given collector and emits values into it. This method should never be implemented or used directly.

The only way to implement the Flow interface directly is to extend AbstractFlow. To collect it into a specific collector, either collector.emitAll(flow) or collect { ... } extension should be used. Such limitation ensures that the context preservation property is not violated and prevents most of the developer mistakes related to concurrency, inconsistent flow dispatchers and cancellation.


common source
Link copied to clipboard