Skip to content

Conversation

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

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

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

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

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

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
Contributor

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
Contributor

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
Contributor

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