Is there a convenient way to make a `channelFlow` ...
# coroutines
l
Is there a convenient way to make a
channelFlow
hot? I would like to open a stream but defer the collecting. What I'm currently doing:
Copy code
// cold
fun readByteArrayStream(): Flow<ByteArray> = channelFlow { .. }

// hot
val bytesChannel: Channel<ByteArray> by lazy { Channel(Channel.UNLIMITED) }

suspend fun openByteArrayStream() {
        readByteArrayStream().onEach { bytesChannel.trySend(it) }.collect()
    }
a
.produceIn
?
👍 1
l
Cool, looks good. The coroutines/flow API is so huge, wasn't aware of this method. Thanks boss!
👍 2