How to emit Flow value from different function? Kotlin Coroutines
问题 I have a flow : val myflow = kotlinx.coroutines.flow.flow<Message>{} and want to emit values with function: override suspend fun sendMessage(chat: Chat, message: Message) { myflow.emit(message) } But compiler does not allow me to do this, is there any workarounds to solve this problem? 回答1: The answer of Animesh Sahu is pretty much correct. You can also return a Channel as a flow (see consumeAsFlow or asFlow on a BroadcastChannel). But there is also a thing called StateFlow currently in