Skip to content

Commit d265290

Browse files
committed
clear correct job
1 parent c7810af commit d265290

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

location/src/main/kotlin/io/customer/location/LocationServicesImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal class LocationServicesImpl(
1919
private val scope: CoroutineScope
2020
) : LocationServices {
2121

22+
@Volatile
2223
private var currentLocationJob: Job? = null
2324

2425
override fun setLastKnownLocation(latitude: Double, longitude: Double) {
@@ -49,7 +50,11 @@ internal class LocationServicesImpl(
4950
try {
5051
orchestrator.requestLocationUpdate()
5152
} finally {
52-
currentLocationJob = null
53+
// Only clear if this is still the current job — prevents
54+
// a cancelled job's finally from nulling a newer job's reference
55+
if (currentLocationJob === coroutineContext[Job]) {
56+
currentLocationJob = null
57+
}
5358
}
5459
}
5560
}

0 commit comments

Comments
 (0)