https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

André Thiele

06/05/2021, 7:35 PM
[solved] Where there any changes to callback flow in Kotlin 1.5? The following code stopped working after upgrading to 1.5.10:
Copy code
private fun FusedLocationProviderClient.locationFlow(
    request: LocationRequest
) = callbackFlow<Location> {
    val callback = object : LocationCallback() {
        override fun onLocationResult(result: LocationResult?) {
            Log.e("Got result", "$result")
            result ?: return
            try {
                offer(result.lastLocation)
            } catch (e: Exception) {
                // swallow
            }
        }
    }

    requestLocationUpdates(
        request,
        callback,
        Looper.getMainLooper()
    ).addOnFailureListener { e ->
        close(e) // in case of exception, close the Flow
    }

    // clean up when Flow collection ends
    awaitClose {
        removeLocationUpdates(callback)
    }
}
Seems to have solved itself
16 Views