Skip to content

Conversation

@AlexanderYKuzmin
Copy link

No description provided.

Copy link
Contributor

@antonkazakov antonkazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет. Оставил пару комментов во Вьюмодели, добавь еще, пожалуйста, решение через презентер

}

fun onInitComplete() {
val deferredFact = viewModelScope.async { catsService.getCatFact() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему ты их вынес за пределы launch?

private val _result = MutableLiveData<Result>()
val result: LiveData<Result> get() = _result

private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю оставить CoroutineExceptionHandler длдя необработанных исключений, а socketexction обработать через try/catch или runCatching


viewModelScope.launch(exceptionHandler) {
val catModel = CatModel(deferredFact.await(), deferredImage.await().first())
_result.postValue(Result.Success(catModel))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты тут уже на главном потоке, можно setValue вызвать

added_presenter_logic|fixed_e_handling|and_stuff
added_presenter_logic|fixed_e_handling|and_stuff
@AlexanderYKuzmin
Copy link
Author

Антон, привет. Внес корректировки.

Copy link
Contributor

@antonkazakov antonkazakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Привет. Нужно распараллелить запросы

fun onInitComplete() {
viewModelScope.launch(exceptionHandler) {

val deferredFact = withContext(Dispatchers.IO) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так, а тут же не поправил, у тебя последовательные запросы

@AlexanderYKuzmin
Copy link
Author

Распараллелил запросы.

}
}

val deferredImage = async(Dispatchers.IO) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно не переключать диспатчер для таких библиотек как рум и ретрофит и любых других что из коробки сапортят саспенд функции

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants