Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
api/ | H | 25-Apr-2025 | - | 9 | 7 | |
src/ | H | 25-Apr-2025 | - | 163 | 100 | |
test/ | H | 25-Apr-2025 | - | 443 | 350 | |
README.md | H A D | 25-Apr-2025 | 1.7 KiB | 46 | 32 | |
build.gradle.kts | H A D | 25-Apr-2025 | 447 | 19 | 13 | |
package.list | H A D | 25-Apr-2025 | 28 | 1 | 1 |
README.md
1# Module kotlinx-coroutines-play-services 2 3Integration with Google Play Services [Tasks API](https://developers.google.com/android/guides/tasks). 4 5Extension functions: 6 7| **Name** | **Description** 8| -------- | --------------- 9| [Task.asDeferred][asDeferred] | Converts a Task into a Deferred 10| [Task.await][await] | Awaits for completion of the Task (cancellable) 11| [Deferred.asTask][asTask] | Converts a deferred value to a Task 12 13## Example 14 15Using Firebase APIs becomes simple: 16 17```kotlin 18FirebaseAuth.getInstance().signInAnonymously().await() 19val snapshot = try { 20 FirebaseFirestore.getInstance().document("users/$id").get().await() // Cancellable await 21} catch (e: FirebaseFirestoreException) { 22 // Handle exception 23 return@async 24} 25 26// Do stuff 27``` 28 29If the `Task` supports cancellation via passing a `CancellationToken`, pass the corresponding `CancellationTokenSource` to `asDeferred` or `await` to support bi-directional cancellation: 30 31```kotlin 32val cancellationTokenSource = CancellationTokenSource() 33val currentLocationTask = fusedLocationProviderClient.getCurrentLocation(PRIORITY_HIGH_ACCURACY, cancellationTokenSource.token) 34val currentLocation = currentLocationTask.await(cancellationTokenSource) // cancelling `await` also cancels `currentLocationTask`, and vice versa 35``` 36 37 38<!--- MODULE kotlinx-coroutines-play-services --> 39<!--- INDEX kotlinx.coroutines.tasks --> 40 41[asDeferred]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-deferred.html 42[await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/await.html 43[asTask]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-play-services/kotlinx.coroutines.tasks/as-task.html 44 45<!--- END --> 46