From a19e8eb8b85ad9ce4c93c2b13cc939c023b0b1bc Mon Sep 17 00:00:00 2001 From: Karan Sharma <55722391+ksharma-xyz@users.noreply.github.com> Date: Fri, 28 Feb 2025 01:21:38 +1100 Subject: [PATCH] Ensure app start task is launched in parallel with other SplashViewModel tasks --- .../xyz/ksharma/krail/splash/SplashViewModel.kt | 11 ++++++++--- .../xyz/ksharma/krail/core/appstart/RealAppstart.kt | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/xyz/ksharma/krail/splash/SplashViewModel.kt b/composeApp/src/commonMain/kotlin/xyz/ksharma/krail/splash/SplashViewModel.kt index 05e15d6f..c30e69c6 100644 --- a/composeApp/src/commonMain/kotlin/xyz/ksharma/krail/splash/SplashViewModel.kt +++ b/composeApp/src/commonMain/kotlin/xyz/ksharma/krail/splash/SplashViewModel.kt @@ -3,6 +3,7 @@ package xyz.ksharma.krail.splash import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -33,9 +34,13 @@ class SplashViewModel( private val _isLoading: MutableStateFlow = MutableStateFlow(false) val isLoading: StateFlow = _isLoading .onStart { - loadKrailThemeStyle() - trackAppStartEvent() - appStart.start() + coroutineScope { + appStart.start() + } + coroutineScope { + loadKrailThemeStyle() + trackAppStartEvent() + } }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), true) private suspend fun trackAppStartEvent() = with(appInfoProvider.getAppInfo()) { diff --git a/core/app-start/src/commonMain/kotlin/xyz/ksharma/krail/core/appstart/RealAppstart.kt b/core/app-start/src/commonMain/kotlin/xyz/ksharma/krail/core/appstart/RealAppstart.kt index cce6b0e2..f20dfe35 100644 --- a/core/app-start/src/commonMain/kotlin/xyz/ksharma/krail/core/appstart/RealAppstart.kt +++ b/core/app-start/src/commonMain/kotlin/xyz/ksharma/krail/core/appstart/RealAppstart.kt @@ -1,6 +1,7 @@ package xyz.ksharma.krail.core.appstart import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import xyz.ksharma.krail.core.log.log import xyz.ksharma.krail.core.remote_config.RemoteConfig