diff options
author | Isidro Henoch <imhenoch@protonmail.com> | 2022-01-31 17:42:26 -0600 |
---|---|---|
committer | Isidro Henoch <imhenoch@protonmail.com> | 2022-01-31 17:42:26 -0600 |
commit | 92ab928f9efd238be7232ee4ec5962bfbb5a0e12 (patch) | |
tree | 3dcca296c05f575f0673bf4028907126134d9670 /shared/src/commonMain/kotlin | |
parent | 7f1388bc554a3ee68a1865d2a219395805a79575 (diff) | |
download | etbsa-trackermap-mobile-92ab928f9efd238be7232ee4ec5962bfbb5a0e12.tar.gz etbsa-trackermap-mobile-92ab928f9efd238be7232ee4ec5962bfbb5a0e12.tar.bz2 etbsa-trackermap-mobile-92ab928f9efd238be7232ee4ec5962bfbb5a0e12.zip |
Tries to fix the units update issue
Diffstat (limited to 'shared/src/commonMain/kotlin')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt index b282a34..e74c7c4 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -32,6 +32,7 @@ import mx.trackermap.TrackerMap.client.models.UnitInformation import mx.trackermap.TrackerMap.utils.Coroutines import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime +import kotlinx.coroutines.Job @DelicateCoroutinesApi @ExperimentalTime @@ -47,6 +48,8 @@ class UnitsController( private val unitsFlow = MutableStateFlow<List<UnitInformation>>(emptyList()) private val queryFlow = MutableStateFlow("") + private var unitsUpdateJob: Job? = null + init { GlobalScope.launch { fetchUnits(this) @@ -57,7 +60,7 @@ class UnitsController( } private suspend fun fetchUnits(scope: CoroutineScope) { - Coroutines.tickerFlow(UPDATE_TIME.seconds) + unitsUpdateJob = Coroutines.tickerFlow(UPDATE_TIME.seconds) .map { print("Fetching new positions...\n") positionsApi.positionsGet() @@ -87,6 +90,10 @@ class UnitsController( .launchIn(scope) } + fun stopUpdates() { + unitsUpdateJob?.cancel() + } + fun search(query: String) { queryFlow.value = query } |