diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-31 22:47:33 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-31 22:47:33 -0600 |
commit | 9d753c9fa9e93171206e6036c1889ea17cac9db6 (patch) | |
tree | 8f345aaece8d850f8dea005fd1b039761fcefc92 /shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers | |
parent | 92ab928f9efd238be7232ee4ec5962bfbb5a0e12 (diff) | |
download | etbsa-trackermap-mobile-9d753c9fa9e93171206e6036c1889ea17cac9db6.tar.gz etbsa-trackermap-mobile-9d753c9fa9e93171206e6036c1889ea17cac9db6.tar.bz2 etbsa-trackermap-mobile-9d753c9fa9e93171206e6036c1889ea17cac9db6.zip |
Attach tickerFlow to viewModelScope in an attempt to bind it to app lifecycle more effectively
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt | 13 |
1 files changed, 2 insertions, 11 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 e74c7c4..a5d5bd7 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/controllers/UnitsController.kt @@ -48,19 +48,14 @@ class UnitsController( private val unitsFlow = MutableStateFlow<List<UnitInformation>>(emptyList()) private val queryFlow = MutableStateFlow("") - private var unitsUpdateJob: Job? = null - init { GlobalScope.launch { - fetchUnits(this) - } - GlobalScope.launch { setupFlows() } } - private suspend fun fetchUnits(scope: CoroutineScope) { - unitsUpdateJob = Coroutines.tickerFlow(UPDATE_TIME.seconds) + fun fetchUnits(scope: CoroutineScope) { + Coroutines.tickerFlow(UPDATE_TIME.seconds) .map { print("Fetching new positions...\n") positionsApi.positionsGet() @@ -90,10 +85,6 @@ class UnitsController( .launchIn(scope) } - fun stopUpdates() { - unitsUpdateJob?.cancel() - } - fun search(query: String) { queryFlow.value = query } |