produceIn

fun <T> Flow<T>.produceIn(scope: CoroutineScope): ReceiveChannel<T>

Creates a produce coroutine that collects the given flow.

This transformation is stateful, it launches a produce coroutine that collects the given flow, and has the same behavior:

  • if collecting the flow throws, the channel will be closed with that exception

  • if the ReceiveChannel is cancelled, the collection of the flow will be cancelled

  • if collecting the flow completes normally, the ReceiveChannel will be closed normally

A channel with default buffer size is created. Use buffer operator on the flow before calling produceIn to specify a value other than default and to control what happens when data is produced faster than it is consumed, that is to control backpressure behavior.

Sources

common source
Link copied to clipboard