-
Notifications
You must be signed in to change notification settings - Fork 237
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
base: development
Are you sure you want to change the base?
HW_1_Kuzmin #174
Conversation
There was a problem hiding this 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() } |
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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
Антон, привет. Внес корректировки. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так, а тут же не поправил, у тебя последовательные запросы
Распараллелил запросы. |
} | ||
} | ||
|
||
val deferredImage = async(Dispatchers.IO) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно не переключать диспатчер для таких библиотек как рум и ретрофит и любых других что из коробки сапортят саспенд функции
No description provided.