как вызвать функцию в сопрограммах Liveata - PullRequest
0 голосов
/ 12 июля 2020

как я могу вызывать внутренний метод в сопрограммах 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))
        }
    }
}
...