Tuesday, 27 October 2020

ChannelFlow producer scope is not triggered

I have issue with the following code:

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)
        }
    }
}

Above code is working most times and send data from local and remote, but sometimes the producer scope not triggered (it print "#getData called" only)

Please advice!

UPDATE:

and the Flow collected:

CoroutineScope(Dispatchers.IO).launch(AppExceptionHandler.exceptionHandler) {
            prescriptionsRepository
                    .getData()
                    .collect {
                        educationWithSponsorsLiveData.postValue(it)
                    }

        }


from ChannelFlow producer scope is not triggered

No comments:

Post a Comment