From a50d005f547f0b650db0e3e3ef5b253bd3324cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=84=9D?= Date: Thu, 2 Mar 2023 00:45:18 +0900 Subject: [PATCH] =?UTF-8?q?Issues=20#287=20feat:=20launchIn=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/lighthouse/ui/MainViewModel.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/lighthouse/ui/MainViewModel.kt b/app/src/main/java/com/lighthouse/ui/MainViewModel.kt index 508b2dbf9..714a5014a 100644 --- a/app/src/main/java/com/lighthouse/ui/MainViewModel.kt +++ b/app/src/main/java/com/lighthouse/ui/MainViewModel.kt @@ -6,22 +6,21 @@ import com.lighthouse.domain.usecase.user.IsLoginUserUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow -import kotlinx.coroutines.launch +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import javax.inject.Inject @HiltViewModel internal class MainViewModel @Inject constructor( - private val isLoginUserUseCase: IsLoginUserUseCase + isLoginUserUseCase: IsLoginUserUseCase ) : ViewModel() { private val _isLoginFlow = MutableSharedFlow() val isLoginFlow = _isLoginFlow.asSharedFlow() init { - viewModelScope.launch { - isLoginUserUseCase().collect { isLogin -> - _isLoginFlow.emit(isLogin) - } - } + isLoginUserUseCase() + .onEach { _isLoginFlow.emit(it) } + .launchIn(viewModelScope) } }