You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
2 years ago | |
|---|---|---|
| .. | ||
| api | 2 years ago | |
| src | 2 years ago | |
| test | 2 years ago | |
| README.md | 2 years ago | |
| build.gradle.kts | 2 years ago | |
| package.list | 2 years ago | |
README.md
Module kotlinx-coroutines-play-services
Integration with Google Play Services Tasks API.
Extension functions:
| Name | Description |
|---|---|
| Task.asDeferred | Converts a Task into a Deferred |
| Task.await | Awaits for completion of the Task (cancellable) |
| Deferred.asTask | Converts a deferred value to a Task |
Example
Using Firebase APIs becomes simple:
FirebaseAuth.getInstance().signInAnonymously().await()
val snapshot = try {
FirebaseFirestore.getInstance().document("users/$id").get().await() // Cancellable await
} catch (e: FirebaseFirestoreException) {
// Handle exception
return@async
}
// Do stuff
If the Task supports cancellation via passing a CancellationToken, pass the corresponding CancellationTokenSource to asDeferred or await to support bi-directional cancellation:
val cancellationTokenSource = CancellationTokenSource()
val currentLocationTask = fusedLocationProviderClient.getCurrentLocation(PRIORITY_HIGH_ACCURACY, cancellationTokenSource.token)
val currentLocation = currentLocationTask.await(cancellationTokenSource) // cancelling `await` also cancels `currentLocationTask`, and vice versa