geekdroid-firebase/src/main/java/com/geekorum/geekdroid/gms/Tasks.kt
changeset 35 626c1ea36cb9
parent 20 5d8a0555733d
child 37 8ec7aee97eb6
--- a/geekdroid-firebase/src/main/java/com/geekorum/geekdroid/gms/Tasks.kt	Thu Dec 01 19:52:51 2022 -0400
+++ b/geekdroid-firebase/src/main/java/com/geekorum/geekdroid/gms/Tasks.kt	Wed Dec 07 20:32:30 2022 -0400
@@ -22,13 +22,11 @@
 package com.geekorum.geekdroid.gms
 
 import com.google.android.gms.tasks.Task
-import kotlinx.coroutines.CancellationException
 import kotlinx.coroutines.CompletableDeferred
 import kotlinx.coroutines.Deferred
 import kotlinx.coroutines.suspendCancellableCoroutine
 import kotlin.coroutines.resume
 import kotlin.coroutines.resumeWithException
-import com.google.android.play.core.tasks.Task as PlayCoreTask
 
 /**
  * Await for the result of a [Task]
@@ -84,7 +82,7 @@
 /**
  * Converts this task to an instance of [Deferred].
  */
-fun <T> PlayCoreTask<T>.asDeferred(): Deferred<T> {
+fun <T> Task<T>.asDeferred(): Deferred<T> {
     if (isComplete) {
         val e = exception
         return if (e == null) {
@@ -108,34 +106,3 @@
     return result
 }
 
-/**
- * Awaits for completion of the task without blocking a thread.
- *
- * If the [Job] of the current coroutine is cancelled or completed while this suspending function is waiting, this function
- * stops waiting for the completion stage and immediately resumes with [CancellationException].
- */
-suspend fun <T> PlayCoreTask<T>.await(): T {
-    // fast path
-    if (isComplete) {
-        val e = exception
-        return if (e == null) {
-            @Suppress("UNCHECKED_CAST")
-            result as T
-        } else {
-            throw e
-        }
-    }
-
-    return suspendCancellableCoroutine { cont ->
-        addOnCompleteListener {
-            val e = exception
-            if (e == null) {
-                @Suppress("UNCHECKED_CAST")
-                cont.resume(result as T)
-            } else {
-                cont.resumeWithException(e)
-            }
-        }
-    }
-}
-