Skip to content
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

Using activeSurveyFlow to make flow async #2890

Merged
merged 11 commits into from
Jan 2, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import timber.log.Timber

/** View model for the Data Collection fragment. */
Expand Down Expand Up @@ -97,7 +100,10 @@ internal constructor(
private var shouldLoadFromDraft: Boolean = savedStateHandle[TASK_SHOULD_LOAD_FROM_DRAFT] ?: false
private var draftDeltas: List<ValueDelta>? = null

private val activeSurvey: Survey = requireNotNull(surveyRepository.activeSurvey)
private val activeSurvey: Survey = runBlocking {
surveyRepository.activeSurveyFlow.filterNotNull().first()
}

private val job: Job = activeSurvey.getJob(jobId) ?: error("couldn't retrieve job for $jobId")
private var customLoiName: String?
get() = savedStateHandle[TASK_LOI_NAME_KEY]
Expand Down
Loading