Skip to content

Homework Baturina #164

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 3 commits into
base: development
Choose a base branch
from

Conversation

BaturinaAnna
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.

Оставил пару замечаний

override fun onFailure(call: Call<Fact>, t: Throwable) {
CrashMonitor.trackWarning()
outerScope.launch {
innerScope = CoroutineScope(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.

А иннер скоуп ты зачем делаешь?

_catsView?.populate(CatModel(catFact.await().fact, catImage.await().url))
} catch (exc: SocketTimeoutException) {
_catsView?.makeToast("Не удалось получить ответ от сервером")
} catch (exc: Exception) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Здесь будет также пойман CancellationException, через который работает механизм отмены. Нужно его пробросить дальше, либо не ловить такой общий тип исключений

private val serviceCatImage: CatsService
): ViewModel() {

var result: MutableLiveData<CatsResult> = MutableLiveData()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Наружу нужно показывать иммутабельную версию лайвдаты/стейтфлоу

viewModelScope.launch(exceptionHandler) {
val catFact = async { serviceCatFact.getCatFact() }
val catImage = async { serviceCatImage.getCatImage() }
result.postValue(CatsResult.Success(CatModel(catFact.await().fact, catImage.await().url)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

А зачем тут postValue, ты же уже на главный поток вернулась

}

fun onInitComplete() {
viewModelScope.launch(exceptionHandler) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Добавь обработку исключений через try/catch

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