Skip to content

Commit eea8af6

Browse files
committed
refactor: only expose the await function
1 parent 52bee14 commit eea8af6

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

firebase-common/ktx/ktx.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ dependencies {
4141
implementation project(':firebase-common')
4242
implementation project(':firebase-components')
4343
implementation 'androidx.annotation:annotation:1.1.0'
44-
45-
// We're exposing this library as a transitive dependency so developers can
46-
// get Kotlin Coroutines support out-of-the-box for methods that return a Task
47-
api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion"
44+
implementation "com.google.android.gms:play-services-tasks:18.0.2"
45+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutinesVersion"
4846

4947
testImplementation "org.robolectric:robolectric:$robolectricVersion"
5048
testImplementation 'junit:junit:4.12'

firebase-common/ktx/src/main/kotlin/com/google/firebase/ktx/Firebase.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ package com.google.firebase.ktx
1515

1616
import android.content.Context
1717
import androidx.annotation.Keep
18+
import com.google.android.gms.tasks.Task
1819
import com.google.firebase.FirebaseApp
1920
import com.google.firebase.FirebaseOptions
2021
import com.google.firebase.components.Component
2122
import com.google.firebase.components.ComponentRegistrar
2223
import com.google.firebase.platforminfo.LibraryVersionComponent
24+
import kotlinx.coroutines.tasks.await
2325

2426
/**
2527
* Single access point to all firebase SDKs from Kotlin.
@@ -50,6 +52,15 @@ fun Firebase.initialize(context: Context, options: FirebaseOptions, name: String
5052
val Firebase.options: FirebaseOptions
5153
get() = Firebase.app.options
5254

55+
/**
56+
* Awaits the completion of the task without blocking a thread.
57+
*
58+
* This suspending function is cancellable.
59+
* If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
60+
* stops waiting for the completion stage and immediately resumes with [CancellationException].
61+
*/
62+
suspend fun <T> Task<T>.await(): T = await()
63+
5364
internal const val LIBRARY_NAME: String = "fire-core-ktx"
5465

5566
/** @suppress */

0 commit comments

Comments
 (0)