AG
08/23/2020, 8:57 AMIllegalStateException Flow invariant is violated emission from another coroutine is detectedflow<Action> {
    val result = downloadFile(url, directory) { event: ProgressEvent ->
        emit(DownloadProgress(event))
    }
    emit(DownloadFinished("path"))
}.onEach { L.d(it) }.launchIn(viewLifecycleOwner.lifecycleScope)suspend fun downloadFile(
    url: String, fileDir: String, onProgressEvent: suspend (event: ProgressEvent) -> Unit = {}) {
 val progressChannel = Channel<ProgressEvent>()
 CoroutineScope(coroutineContext).launch {
     progressChannel.consumeAsFlow().collect { onProgressEvent.invoke(it) }
  }
/* rest of the code */
}Zach Klippenstein (he/him) [MOD]
08/23/2020, 12:01 PMdownloadFileZach Klippenstein (he/him) [MOD]
08/23/2020, 12:02 PMchannel.consumeAsFlow().collect{}channel.consumeEach{}AG
08/23/2020, 1:05 PMAG
08/23/2020, 1:07 PMChannelAG
08/23/2020, 1:11 PMflow<Action> {
    val flowContext = coroutineContext
    val result = downloadFile(url, directory) { event: ProgressEvent ->
        withContext(flowContext){
        emit(DownloadProgress(event))
       }
    }
    emit(DownloadFinished("path"))
}.onEach { L.d(it) }.launchIn(viewLifecycleOwner.lifecycleScope)