Skip to content

Commit

Permalink
Fail gracefully on race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
gino-m committed Mar 1, 2024
1 parent cbda0a4 commit d63d66b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber

/** Main app view, displaying the map and related controls (center cross-hairs, add button, etc). */
@AndroidEntryPoint
Expand Down Expand Up @@ -139,9 +140,13 @@ class HomeScreenMapContainerFragment : AbstractMapContainerFragment() {
* This method should only be called after view creation.
*/
private suspend fun showDataCollectionHint() {
check(this::mapContainerViewModel.isInitialized) { "mapContainerViewModel not initialized" }
check(this::binding.isInitialized) { "binding not initialized" }
if (!this::mapContainerViewModel.isInitialized) {
return Timber.w("showDataCollectionHint() called before mapContainerViewModel initialized")
}
mapContainerViewModel.surveyUpdateFlow.collect {
if (!this::binding.isInitialized) {
return@collect Timber.w("showDataCollectionHint() called before binding initialized")
}
val messageId =
when {
it.addLoiPermitted -> R.string.suggest_data_collection_hint
Expand Down

0 comments on commit d63d66b

Please sign in to comment.