-
Notifications
You must be signed in to change notification settings - Fork 239
Homework done #2
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?
Conversation
} | ||
|
||
override fun onFailure(call: Call<Fact>, t: Throwable) { | ||
catsJob?.cancel() |
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.
Я думаю т.к этот метод вызывается в onCreate
здесь cancel
можно убрать. Т.к если активити пересоздастся то у тебя в любом случае будет другой инстанс презентера и Job
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.
onInitComplete еще вызывается по нажатию кнопки, таким образом мы запускаем новую корутину не останавливая старую. Верно?
|
||
override fun onFailure(call: Call<Fact>, t: Throwable) { | ||
catsJob?.cancel() | ||
catsJob = PresenterScope().launch { |
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.
Лучше не создавать каждый раз новый инстанс, и переместить его в тело класса. И отменять не джобу, а сразу скоуп
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 fact = async { catsService.getCatFact() } | ||
val image = async { imageService.getRandomImage()} | ||
_catsView?.populate(CatsModel(fact.await(), image.await())) | ||
} catch (socketEx: SocketTimeoutException){ |
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.
Вкусовщина: можно в одном catch
написать when
блок и проверять по типу эксепшена.
|
||
private val catInfo: MutableLiveData<Result> = MutableLiveData<Result>() | ||
private val exceptionHandler = CoroutineExceptionHandler() { _, exception -> | ||
catInfo.value = Error(exception.localizedMessage ?: "An error occurred") |
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.
Наверное непонятно описал условия. Нужно обработать java.net.SocketTimeoutException
эксепшен и вернуть Result.Error(message)
, а в случае другого типа эксепшена вызвать CrashMonitor
try { | ||
val fact = async { handleResponse(catsService.getCatFact()) | ||
} | ||
val image = async { handleResponse(imageService.getRandomImage()) } |
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 fact = catsScope.async { handleResponse(catsService.getCatFact()) }
val image = catsScope.async { handleResponse(imageService.getRandomImage()) }
иначе при отсутствии интернета будет креш
3 subtasks done, 1 commit per each.
Boris Lunyakov