Skip to content

HW_1_Kuzmin #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

AlexanderYKuzmin
Copy link

No description provided.

Copy link
Collaborator

@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
Collaborator

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
Collaborator

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
Collaborator

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
Collaborator

@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
Collaborator

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
Collaborator

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