As an example, I'm using FusedLocationProviderClient to access the current location, which returns a task which callback will eventually return the location. The method looks something like follows:
fun getLocation(callback: MyCallback){ val flpc = LocationServices.getFusedLocationProviderClient(it) flpc.lastLocation.addOnSuccessListener { callback.onLocation(it) } } Is it possible to transform this so that I can use corroutines to suspend this function and wait for the task returned by flpc.lastLocation so I can return it in this method and this way get rid of that callback? For example something like this:
suspend fun getLocation(): Location? = withContext(Dispachers.IO){ val flpc = LocationServices.getFusedLocationProviderClient(it) return@withContext flpc.lastLocation.result() } My question is if there is something around coroutines where I can return the result of a Task (in this example, a Task<Location>)
Thanks in advance!