Skip to content

Commit

Permalink
fest(ArtistDetailViewModel): 데이터를 비동기로 요청한다
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Apr 3, 2024
1 parent f37d533 commit da184a5
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.festago.festago.presentation.ui.artistdetail.uistate.ArtistDetailUiSt
import com.festago.festago.presentation.ui.artistdetail.uistate.ArtistUiState
import com.festago.festago.presentation.ui.artistdetail.uistate.FestivalItemUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.async
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
Expand All @@ -33,9 +34,13 @@ class ArtistDetailViewModel @Inject constructor(

viewModelScope.launch {
runCatching {
val deferredArtistDetail =
async { artistRepository.loadArtistDetail(id).getOrThrow() }
val deferredFestivals =
async { artistRepository.loadArtistFestivals(id, 10).getOrThrow().toUiState() }
_uiState.value = ArtistDetailUiState.Success(
artistRepository.loadArtistDetail(id).getOrThrow(),
artistRepository.loadArtistFestivals(id, 20).getOrThrow().toUiState(),
deferredArtistDetail.await(),
deferredFestivals.await(),
)
}.onFailure {
_uiState.value = ArtistDetailUiState.Error
Expand Down

0 comments on commit da184a5

Please sign in to comment.