Android 未触发ChannelFlow生成器作用域

Android 未触发ChannelFlow生成器作用域,android,kotlin,kotlin-coroutines,Android,Kotlin,Kotlin Coroutines,我对以下代码有异议: suspend fun getData(): Flow<Resource<User>> { println("#getData called") return channelFlow { println("#getData producer scope started") launch(Dispatchers.IO) { val cach

我对以下代码有异议:

suspend fun getData(): Flow<Resource<User>> {
    println("#getData called")
    return channelFlow {
        println("#getData producer scope started")

        launch(Dispatchers.IO) {
            val cachedData = sharedPreferencesUtils.getData()
            println("#getData send cached data")
            send(cachedData)
        }

        launch(Dispatchers.IO) {
            val response = handleAPI<EducationResponse> { apiService.getData() }
            println("#getData send remote data")
            send(response)
        }
    }
}

您需要包括使用
getData()
的地方,流是冷的,只有在被收集的情况下才能执行某些操作。@Kiskae流是从调用它的所有地方收集的(实际上我是从viewModel调用它),请检查上面收集通道的代码。注意:这种情况并不总是发生,我无法在已知场景中重现这种情况,它突然出现了!
CoroutineScope(Dispatchers.IO).launch(AppExceptionHandler.exceptionHandler) {
            prescriptionsRepository
                    .getData()
                    .collect {
                        educationWithSponsorsLiveData.postValue(it)
                    }

        }