Skip to content

HW Sokolova_coroutines #156

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

Conversation

Sokolik411
Copy link

No description provided.

@Sokolik411 Sokolik411 closed this Jul 11, 2023
@Sokolik411 Sokolik411 reopened this Jul 11, 2023
@Sokolik411 Sokolik411 force-pushed the coroutines_vsokolova branch from 2d783f3 to 9d47eed Compare July 13, 2023 19:59
@Sokolik411 Sokolik411 force-pushed the coroutines_vsokolova branch from 9d47eed to fcdfbfb Compare July 13, 2023 20:05
Copy link

@invweb invweb left a comment

Choose a reason for hiding this comment

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

В целом - нормально. Ещё чуть поправить и будет хорошо.

@Sokolik411 Sokolik411 force-pushed the coroutines_vsokolova branch 2 times, most recently from 68f873a to b074ef4 Compare July 14, 2023 18:58
@Sokolik411 Sokolik411 force-pushed the coroutines_vsokolova branch from b074ef4 to 796be51 Compare July 15, 2023 08:19
Copy link

@invweb invweb left a comment

Choose a reason for hiding this comment

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

всё хорошо

Copy link

@invweb invweb left a comment

Choose a reason for hiding this comment

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

всё хорошо

private val factService: CatsFactService,
private val imageService: CatsImageService
) : ViewModel() {
val catModel = MutableLiveData<Result>()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Мутабельные стримы: лайвдата, стейтфлоу и тп делают приватными(обычно). Это для того чтобы у тебя в стрим мог эмитить только 1 класс, а не все у кого есть ссылка на CatViewModel.

Copy link
Author

Choose a reason for hiding this comment

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

d

is SocketTimeoutException -> {
catModel.value = Result.Error(Throwable(Resources.getSystem().getString(R.string.error_connection)))
}
is CancellationException -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

в CoroutineExceptionHandler этого можно не делать, справедливо только для обычного catch

Copy link
Author

@Sokolik411 Sokolik411 Aug 14, 2023

Choose a reason for hiding this comment

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

d, унесла в try/catch


private val handler = CoroutineExceptionHandler { _, throwable ->
when (throwable) {
is SocketTimeoutException -> {
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. Тут оставил только необработанные

Copy link
Author

Choose a reason for hiding this comment

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

d


override fun onCleared() {
super.onCleared()
viewModelScope.cancel()
Copy link
Collaborator

Choose a reason for hiding this comment

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

viewModelScope сам будет очищен в onCleared

Copy link
Author

Choose a reason for hiding this comment

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

d

interface CatsFactService {

@GET("fact")
suspend fun getCatFact() : Response<Fact>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Я бы просто Fact оставил

Copy link
Author

Choose a reason for hiding this comment

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

d, для картинок сделала аналогично

override fun onResponse(call: Call<Fact>, response: Response<Fact>) {
if (response.isSuccessful && response.body() != null) {
_catsView?.populate(response.body()!!)
runBlocking(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.

Зачем здесь runBlocking? Его вообще кроме как в тестах использовать нигде не нужно

Copy link
Author

Choose a reason for hiding this comment

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

d


fun onStop(){
catsScope.cancel()
Copy link
Collaborator

Choose a reason for hiding this comment

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

А почему это не перенести в detachView, ты же onStop вызываешь в onStop ЖЦ

Copy link
Author

Choose a reason for hiding this comment

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

d

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.

4 participants