File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
data/src/main/java/com/github/umercodez/sensorspot/data/sensorpublisher Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,9 @@ class SensorPublisher(
9595 }
9696 suspend fun connectAndPublish (mqttConfig : MqttConfig ) = withContext(ioDispatcher){
9797
98+ sensorEventCollectionJob?.cancel()
99+ gpsDataCollectionJob?.cancel()
100+
98101 sensorEventCollectionJob = scope.launch {
99102 sensorEventProvider.events.collect { sensorEvent ->
100103
@@ -191,6 +194,9 @@ class SensorPublisher(
191194 }
192195 exception?.printStackTrace()
193196
197+ sensorEventCollectionJob?.cancel()
198+ gpsDataCollectionJob?.cancel()
199+
194200 }
195201
196202 })
@@ -200,6 +206,9 @@ class SensorPublisher(
200206 scope.launch {
201207 _mqttConnectionState .emit(MqttConnectionState .ConnectionError (e))
202208 }
209+
210+ sensorEventCollectionJob?.cancel()
211+ gpsDataCollectionJob?.cancel()
203212 }
204213
205214 }
@@ -230,6 +239,8 @@ class SensorPublisher(
230239 _mqttConnectionState .emit(MqttConnectionState .ConnectionError (exception))
231240 }
232241 exception?.printStackTrace()
242+ sensorEventCollectionJob?.cancel()
243+ gpsDataCollectionJob?.cancel()
233244 }
234245
235246 override fun messageArrived (topic : String? , message : MqttMessage ? ) {
You can’t perform that action at this time.
0 commit comments