如何多次在liveData协程中调用内部方法
我想每次调用此函数时都调用这部分代码:
try {
emit(LiveDataResult.Success(configApi.getConfig(ConfigurationRequest())))
} catch (exception: Exception) {
emit(LiveDataResult.Failure(exception.message, exception))
}
在此功能中:
fun getConfig(): LiveData<LiveDataResult<ConfigurationResponse>?> {
return liveData<LiveDataResult<ConfigurationResponse>?>(dispatcher.IO) {
emit(
LiveDataResult.Success(
cacheHelper.getApiResponse(
GET_CONFIG,
ConfigurationResponse::class.java
)
)
)
try {
emit(LiveDataResult.Success(configApi.getConfig(ConfigurationRequest())))
} catch (exception: Exception) {
emit(LiveDataResult.Failure(exception.message, exception))
}
}
}